Hi, I am working on a refined search feature and I am having a little problem with the following code. I'm trying to get the "genre" values from the form. Then use them in a query to refine the results from the database. The problem is as follows.
I need "$str" to pass the values from the form like this:
AND genre IN ('other','metal','pop')';
But, with multiple selected boxes "$str" passes them like this:
AND genre IN ('other,metal,pop')';
Any help would be great!
SIDE NOTE:If one checkbox is selected, it works fine.
<?
if(isset($_REQUEST['submit']))
{
$str = ' 1=1 ';
if( count($_POST['genre']) > 0 )
{
$genre = implode(',',$_POST['genre']);
$str.= ' AND genre IN ('.$genre.')';
echo $sql = "SELECT * FROM uploads WHERE ".$str;
}
}
?>
<form name="form" id="form" method="post" action="">
genre:
<input type="checkbox" checked="checked" name="genreAny[]" value="Any">Any
<input type="checkbox" name="genre[]" value="other">other
<input type="checkbox" name="genre[]" value="metal">metal
<input type="checkbox" name="genre[]" value="pop">pop
<br>
<input name="submit" value="Search" type="submit">
</form>