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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.