I have this foreach loop, that I use for a search feature:
$keywords=$_GET['keyword'];
$exploded=explode(' ',trim($keywords));
$mysql_command="SELECT * FROM items WHERE completed='1' AND ";
foreach ($exploded as $key => $value){
if ($key>0)
$mysql_command.=' OR ';
$mysql_command.="title LIKE ? OR description LIKE ?";
}
I want to use this prepared statement:
$stmt=$cxn->prepare($mysql_command);
$stmt->execute(array("%$value%","%$value%"));
The problem is, I don’t know how many keywords there is going to be. So how can I make a prepared statement with an unknown number of keywords?
Thanks a lot in advance. Regards
Why you don’t create the array after the request like this :