Dear experts, Let say I have to search 3 co-related options 1)name 2)address 3)Phone. So, I have to write 8[eight] separate queries.pls see the example below….
$name= $_POST['name'];
$address = $_POST['address'];
$phone= $_POST['phone'];
if($name!=""&& $address==""&& $phone=="")
{ $searching_query="SELECT id,name,address from info where info LIKE '%$info%'";}
.....................................
......................................
..........................................
else if($name!=""&&$address==""&&$phone!="")
{ $searching_query="SELECT id,name,address from info where name LIKE '%$ name%' AND phone LIKE '$phone' "; }
else if ($name!=""&&$address!=""&&$phone!="")
{ $searching_query="SELECT id,name,address from info where name LIKE '%$ name%' AND address LIKE '%$address%' AND phone LIKE '$phone' ";}
So, if the correlated searching option is more than that then I have to write more and more queries.
Now my question is: how can I write the exact query dynamically. I mean WHERE clause of query will be generated based on posted values.
Please help! Thx,riad