I have two select boxes with the search button. In One select box is fruit
and a second is car
. Now the issue is 1) If anyone select from the first select box and second select box then displays all records (Means it will display all fruit and car records). 2) If anyone select only First select box then display all records(Means it will display only fruit records) or 3) select second select box then display all records(Means it will display all car records).
Below query, I tried it is displaying It is working for the First issue
SELECT * FROM request WHERE fruit='$fruit' and car='$car'
I need a query for 2) and 3) in single query. Would you help me in this?
for this you need to develop a little logic I am guessing as POST method
if(isset($_POST['search']))
{
$con =" 1=1 ";
if(!empty($_POST['fruit']) && !empty($_POST['car'])){
$con .=" and want_to_learn='".$_POST['fruit']."' and expert_in='".$_POST['car']."'";
}
else if(!empty($_POST['fruit'])){
$con .=" and want_to_learn='".$_POST['fruit']."'";
}
else if(!empty($_POST['car'])){
$con .=" and expert_in='".$_POST['car']."'";
}
$search_sql="SELECT * FROM request WHERE ".$con ;
$search_result = $conn->query($search_sql);
}