i want same code with switch case.
if($fromdate && $todate)
{
/* Search by Only By Date*/
$sql="SELECT * FROM child_information
INNER JOIN gurdian_information ON gurdian_information.patient_id=child_information.patient_id
where (child_information.date between ‘$fromdate’ and ‘$todate’) ";
}
elseif($status)
{
$sql="SELECT * FROM child_information
INNER JOIN gurdian_information ON gurdian_information.patient_id=child_information.patient_id
where child_information.status=’$status’ ";
}
elseif($name)
{
$sql="SELECT * FROM child_information
INNER JOIN gurdian_information ON gurdian_information.patient_id=child_information.patient_id
where child_information.name=’$name’ ";
}
elseif($fathername)
{
$sql="SELECT * FROM child_information
INNER JOIN gurdian_information ON gurdian_information.patient_id=child_information.patient_id
where child_information.fathername=’$fathername’ ";
}
elseif($gender)
{
$sql="SELECT * FROM child_information
INNER JOIN gurdian_information ON gurdian_information.patient_id=child_information.patient_id
where child_information.gender=’$gender’ ";
}
The switch statement is similar as a series of IF statements on the <b>same expression</b>. Many times, you may want to compare the same expression with many different values, and execute a different piece of code depending on which value it equals to. In that case we use switch statement specifically.