hello...i have problem....I want retrieve data black blue red from database using sql In operator but I don't know how..... $color="black blue red"; $query=mysql_query("SELECT * FROM table WHERE color IN ('black','blue','red' )"; while($row = mysql_fetch_array($query)) { echo "color :".$row['color']." number:".$row['number']."<br/>" ; } ?> PHP:
I would imagine this to work just fine for what you want to do. $colors = "black blue red"; $colors = "'".str_replace(' ', "', '", $colors)."'"; $sql = sprintf("SELECT * FROM `table` WHERE `color` IN (%s);", $colors); $result = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { echo 'Color: '.$row['color'].' Number:'.$row['number'].'<br />'; } PHP: