I'm trying to create a simple search field, in which the user can write a text. This text gets transfered to php which then accesses the text through GET. If the text contains whitespaces it gets converted in to an array. The problem is that I can't figure out how to query for entries with an array as the Where condition. I tried several answers like implode(",",$array) or WHERE IN($array). None of them worked for me. Either I get array to string comparison errors or unkown colum errors. The $_GET array contains the string submitted by the form, so that's not the error.
Thanks for your help!
PHP Script
//string containing the submitted searchbox value
$query=$_GET['Searchquery'];
//Seperate string where whitespaces are detected and create array holding these strings
$querystring=explode(" ",$query);
//Connection
$con=new mysqli($Server,$User,$UserPassword,$Database);
//print_r for testing
print_r($querystring);
//That's the problem
$sql="SELECT * FROM tb_user WHERE ??????"
if($result=$con->query($sql))
{
$word;
//Check if query result is one or multiple entries
if($result->num_rows==1)
$word="entry";
else
$word="entries";
//output_____________
echo("<h1>We found ".$result->num_rows." ".$word." meeting your Keyword '".$query."'</h1>");
while($row=$result->fetch_assoc())
{
echo("<div id='founduser'><a href='profile.php?ProfileLink=".$row['ProfileLink']."'><h1>".$row['GivenName']." ".$row['FamilyName']."</h1></a></div>");
}
}
//______________________________
else {
echo($con->error);
}
?>