I'm creating a html form that allows the user to search for people in a database. I want the form to work with drop down selects and radio buttons. Currently I'm using an if { } elseif {} else if{} format to my script.
However this causes a problem because I have to set up individual if statements for a multiple of variables. For example: Age is a drop down, so is sex, so is height. The radio buttons, for example, would be yes - smoker, yes-drinks etc.
I end up with a script sort of like this expert (minus the radio buttons) but with more variables and more requests from the database:
if (($ageF == 'No Preference') && ($sexF == 'No Preference') && ($hairF == 'No Preference') && ($DressF == 'No Preference'))
{
$result=mysql_query("SELECT * FROM People ORDER by Name") or die(mysql_error());
}
else if (( $ageF != 'No Preference') && ($sexF == 'No Preference') && ($hairF == 'No Preference') && ($DressF == 'No Preferencce'))
{
$result=mysql_query("SELECT * FROM People WHERE Age='".$ageF."'") or die(mysql_error());
}
The variables are correct and its working so far. I just know there must be an easier way and would like to learn the correct way to do it.
Any suggestions on how I should set up the php script that handles the html form?