Jump to content

Need help with PHP and MySql query


svgmx5

Recommended Posts

I have this query that searches the database based on what the user inputed.

 

However i'm having the following issues with it:

 

 

The query is supposed to look for the name of a city in a database table that stores the city names along with their state and country

 

CITY

STATE

COUNTRY

 

Now i have an input field where the user can search a location and it searches the location from the database. When they search the database the input is in the following format:

 

city, state, country

 

I then use the following script to separate them into three fields

$split = explode(',', $location); // $location being the city, state, country
$city = $split[0];
$state = $split[1];
$country = $split[2];

 

Then i use this MySql Query to search the fields to make sure the city and country match

$get_location = mysql_query("SELECT * FROM locations WHERE name LIKE '$city' AND country LIKE '$country'") or die(mysql_error());
$tmp_loc = mysql_fetch_assoc($get_location);

 

This is where the problem beings...if i use "AND" to search both fields i get no results even though there are results in there however if i change it to an "OR" statement it finds teh locations however it doesn't do an accurate search...

 

for example someone searches for Toledo, Ohio, United States, the user will get Toledo, Spain instead of the right Toledo, since Toled, Spain is at the top of the table

 

I've been trying to get this but i can't get this to work at all every time i use AND it gives me no results

 

I hope someone here can check help me out

 

 

Link to comment
https://forums.phpfreaks.com/topic/229572-need-help-with-php-and-mysql-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.