2

I'm having an issue with search.php. I am wondering how to parse $_GET["geo"] so that it can find cities with a space in the name (i.e. New York, San Diego). I used the 'LIKE' sql command and strtok() to separate the tokens(with a " " and a "," as the delimiters) and then compare them to the names in the places database. It works all but perfectly for queries like "Cambridge Massachusetts" or "Fresno, CA" or even just a zip or a city name.

Using this method for dividing up the queries won't work since "New" and "San" aren't going to represent any place name, or admin name in the database. I have been looking through this thread and the cs50 subreddit for some one with a similar issue but I haven't found anyone having this issue. Should I be using a different function to separate the "geo" query or a different method for comparing the SQL. Any suggestions would be helpful. Thanks.

2 Answers 2

0
  1. thank you for your question! I wouldn't notice this problem if you didn't post it.
  2. I googled it and found this is somehow working:

"SELECT ID, FirstName, LastName FROM Contacts WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";

(see http://www.webreference.com/programming/php/search/2.html)

Good luck :)

0

I added (with some conditions!)

"OR place_name LIKE '" . htmlspecialchars($location[$int - 1], ENT_QUOTES) . 
" " . htmlspecialchars($location[$int], ENT_QUOTES) . "%'"

and

"OR place_name LIKE '" . htmlspecialchars($location[$int], ENT_QUOTES) .
" " . htmlspecialchars($location[$int + 1], ENT_QUOTES) . "%'"

I hope this helps you. I needed some time to fix the same error - and I'm sure there is a simpler way, but I haven't found it yet.

You must log in to answer this question.

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