Hello i have a form with 6 fields:
Age1
Age2
Client type
Destination
Score1
Score2
I want to create a query based on what fields are completed and i don't know how to create one only by creating for each posibility a query. Those form fields are colums in my database of 2 tables.
$age1=$_POST['age1'];
$age2=$_POST['age2'];
$score1=$_POST['score1'];
$score2=$_POST['score2'];
$destination=$_POST['destionation'];
$client_type=$_POST['client_type'];
if ($age1!='' and $age2!='')
{
$age_sql=" where TIMESTAMPDIFF(year, Bday,CURDATE())>=$age1 and TIMESTAMPDIFF(year, Bday,CURDATE())<=$age2";
}
if ($destination!='')
{
$dest_sql='Inner Join Leg_Client_Destinatie
where Leg_Client_Destinatie.Destinatie="'.$destinatie.'"
and Leg_Client_Destinatie.ID=Persoane.ID';
}
$stmt = $dbh->prepare("SELECT * from Persoane $dest_sql $varsta_sql");
$stmt->execute();
while ($row = $stmt->fetch())
{
}
but this is not a good solution to make for each posibility because there can be alot of combinations. Any of you have another ideea?