Hello everyone…I stumbled on a little problem trying to retrieve records using the where field IN() .
I have a table called listings and a field within the table called prop_type. The field type is set to SET and the values are ‘commercial’,’residential’ etc so when looking at it in the structure view of the table in phpmyadmin the type looks like set('commercial', 'residential')…
I’m trying to query this table with a search form that uses two or more check boxes
<input type="checkbox" value="commercial" name=" prop_type []"><input type="checkbox" value=" residential " name=" prop_type []">
foreach ($_POST['prop_type'] as $pt) {
$in1 .= "'" . $pt . "',";
}
$in1 = substr($in1,0,strlen($in1)-1); // the we strip the final comma.
$query = "SELECT * FROM listings WHERE prop_type IN (" . $in1 . ");
$result = mysql_query($query);
I have two records stored. One record has both commercial and residential and the other just has commercial. When I query from the search form by checking the commercial checkbox only, I retrieve the record which has just commercial.
SQL Print out by echo:
SELECT * FROM listings WHERE prop_type IN (‘commercial’)
Is there another way to do this or why this is?
Thanks