Forum Moderators: coopster
I would like my users to choose which fields they search from, eg search for "red" in field1, field2 and field7 only.
I would use checkboxes for this, using [], eg:
<input type="checkbox" id="field[]" value="field1">Field 1
I understand I would have to split the $field array (on the comma delimiter?) and then use it in my SQL statement. Would it be something like this?
foreach($fieldarray as $key=>$value)
{
$sql = "SELECT * FROM table WHERE $fieldarray[i] LIKE '%$searchword%'";
}
I have no idea of the correct syntax.
I hope someone can help.
Thanks,
Maynard.
If this is right, try something like this..
foreach($field as $key => $col_value) {
$sql = "SELECT * FROM table WHERE `$key` LIKE '%$searchword%'";
}
well with this solution you will make N sql queries...
I think you will add the checked field to your query like this:
$query = "SELECT * FROM table WHERE ";
foreach($fieldarray as $key=>$value)
{
$query .= $key." LIKE '%".$value."%' AND ";
}
$query = substr($query,0,-4); //kill last AND
echo $query;
hope this helps :)
regards