0

Hello I have trouble to do any debuging in search.php pset8. In previous problems there where always some way to print my variables and figure out what was wrong with my querys och logics. However in this file I can not use print_r(); as I did before in the php files. I got a suggestion to use var_dump(); but that did not work either.

What I in particular want to do right now is print my $places variable to see how query is being handled.

0

It's even easier than that.

The search.php code is already printing the contents of the $places variable as JavaScript Object Notation:

// output places as JSON (pretty-printed for debugging convenience)
header("Content-type: application/json");
print(json_encode($places, JSON_PRETTY_PRINT));

To view this output, you don't need to add any debugging statements to your code. All you need to do is view the URL in a browser, appending an appropriate query string to the URL as input.

Here's what they say about it in the Problem Specification:

To test search.php, even before your text box is operational, simply visit URLs like

https://ide50-username.cs50.io/search.php?geo=Cambridge,Massachusetts,US

https://ide50-username.cs50.io/search.php?geo=Cambridge,+Massachusetts

https://ide50-username.cs50.io/search.php?geo=Cambridge,+MA

https://ide50-username.cs50.io/search.php?geo=Cambridge+MA

https://ide50-username.cs50.io/search.php?geo=02138

or

https://ide50-username.cs50.io/search.php?geo=New+Haven,Connecticut,US

https://ide50-username.cs50.io/search.php?geo=New+Haven,+Massachusetts

https://ide50-username.cs50.io/search.php?geo=New+Have,+MA

https://ide50-username.cs50.io/search.php?geo=New+Haven+MA

https://ide50-username.cs50.io/search.php?geo=06511

and other such variants, where username is your own username, to see if you get back the JSON you expect (and not, say, some big, orange error!). Again, though, we leave it to you to decide just how tolerate search.php will be of abbreviations, punctuation, and the like. The more flexible, though, the better! Try to implement features that you yourself would expect as a user!

Feel free to tinker with the staff’s solution at https://mashup.cs50.net/, inspecting its HTTP requests via Chrome’s Network tab as needed, if unsure how your own code should work!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .