I am trying to setup a search function where i can either type in what i want or i can select it from a drop down menu, however when the fields are blank i want it to show everything.
Right now when i search for something it will work however when the fields are blank it does not show anything at all. I am using prepare and bind_params to setup the mysql query which is why it is making it difficult to setup because if the variable is empty im not sure how to easily remove that section of the query and also change the amount of variables that are being binded to the query. Here is the query
$stmt = $conn->prepare("SELECT * FROM re_tblcombinationlist WHERE active != ? AND ModifierKey = ? AND (LootItem1Key = ? OR LootItem2Key = ? ) ORDER BY ReportedOn DESC LIMIT ? , ?");
$stmt->bind_param("isssii", $i = 0, $modifier, $lootsearch, $lootsearch, $limits, $max);
$recent1 = infoo($stmt);
I tried to solve it by adding this if then statement but it didnt change anything
if(!isset($_POST["modifier"])){
$modifier = '';
}else{
$modifier = clean($_POST["modifier"]);
}
if(!isset($_POST["lootsearch"])){
$lootsearch = '';
}else{
$lootsearch = clean($_POST["lootsearch"]);
}
Basically if modifier or lootsearch are empty i dont want that section to be in the mysql query, which is easy to do however it then makes it very difficult to deal with the amount of variables to bind so i was trying to find a way to make it search everything if the variable is empty.
Thanks
LIKEas the comparison operator, and then simply use%as the “search value” for any empty field …