Jump to content

mysql IN array


scarhand

Recommended Posts

i have 2 tables:

 

ass_name (name, city, state)

ass_city (name, state)

 

the "city" field comprised of an imploded array ', '

 

now the "city" fields value is "Abbeville, Abel, Abernant" in ass_name

 

i am trying to check if "Abel" is in "Abbeville, Abel, Abernant" but my query isn't working

 

heres the code:

 

$state = $_GET['state'];
$sql = mysql_query("SELECT * FROM ass_city WHERE state='$state' ORDER BY name ASC");

while ($row = mysql_fetch_array($sql))
{
  $city = $row['name'];

  $csql = mysql_query("SELECT * FROM ass_name WHERE city IN('$city')");

  if (mysql_num_rows($csql) == 0)
    echo "<input type=\"checkbox\" value=\"$city\"> $city<br />";
  else
    echo "<input type=\"checkbox\" value=\"$city\" disabled> $city (disabled)<br />";
}

Link to comment
https://forums.phpfreaks.com/topic/141942-mysql-in-array/
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.