Jump to content

[SOLVED] Strpos and a MySQL Query


suttercain

Recommended Posts

Hi guys,

 

Right now I am collecting data. The end user can enter up to 5 cites. I then take these cities and import them into MySQL as such:

 

Los Angeles, Corona, Pasadena, Rosemead, Temple City

 

Now let's say there are 100 rows in the column, each with varied cities. Now within 5 of thoses rows Pasadena is listed as a city. How would I query to find all listing that have Pasadena listed as a city?

 

I am cuurently using the get method. So If I was on page 1 and click the link Pasadena, I would be taken to page 2 and a list of all Users who have Pasadena as one of their cities would be echoed.

 

if (isset($_GET['city'])) {
    $city = mysql_real_escape_string($_GET['city']);
    $sql = mysql_query("SELECT * FROM states WHERE city = '" .$city. "' ORDER BY city");
  }
  

while ($row = mysql_fetch_array($sql)) {
echo results
}

 

Currently I don't get any results because pasadena is within a string in the database as Los Angeles, Corona, Pasadena, Rosemead, Temple City. How do I break it down so it only finds Pasadena and not Los Angeles, Corona, Pasadena, Rosemead, Temple City?

 

strpos, explode?

 

Thanks guys!

 

SC

Link to comment
https://forums.phpfreaks.com/topic/62066-solved-strpos-and-a-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.