Hello all,
This is my first time posting here so please be kind and if I have posted in the wrong forum please let me know.
I have been trying to get this search function working for nearly a week now and I hate to admit it but its got me beat
I really don't like asking for help as I like figuring things out myself but I must say I am defeated here and could do with a fresh pair of eyes to help me out (there I said it!)
My problem - Using a checkbox array to search a specific mysql table.
It works till the point of if just one checkbox is selected its great, but two or more is causing a problem.
the form:
Code: Select all
<form action="searchlistings.php" method="post" name="category">
<input type="hidden" name="category" value="1" />
<input type="checkbox" name="list[]" value="beaches" />
<input type="checkbox" name="list[]" value="hotels" />
<input type="checkbox" name="list[]" value="parks" />
</form>Code: Select all
id - location - category - country - state - city - authCode: Select all
if ( $_POST['category'] == 1 ) {
$searchat = category;
if ( $_POST['list'] != '' ) {
$p.="AND ";
}
$checks = $_POST['list'];
if( sizeof( $checks ) ) {
$o.="OR ";
for( $i = 0; $i < count( $checks ); $i++ ) {
if (count($checks) > 1) {
$c.="$searchat like '%$checks[$i]%' $o ";
} else {
$c.="$searchat like '%$checks[$i]%' ";
}
echo "\$checks[$i]: ". $checks[$i]."<br>\n";
}
}
$sql = "SELECT * FROM listings WHERE $c AND auth = 'Yes'";
}Code: Select all
WHERE category LIKE '%beaches%' OR category LIKE '%parks%' OR AND auth = 'Yes'Please feel free to comment on any code mistakes I have made or Improvements you think I should do (if I am asking for help I may as well go all out
Many many thanks in advance
Ross
~pickle | Please use [ php ], [ code=text ] and [ syntax="..." ] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: