I have a php page that contains a form with 7 drop down boxes.
The problem is that the 0 to 6 boxes may be unselected.
It would be a lot of work to make a switch with a case for every combination.
What other method can i use?
thanks,
Sebastian
EDIT
For each combination i have to make different queries that contain only the selected items from the drop-boxes.
Ex. If the user selects 3 from the 7, the query has to pass 3 conditions.
EDIT2
I don’t know what the values of the drop-boxes are. Because they are built up using an mysql query in a while statement
SOLUTION
I’ve found a solution that should work. I haven’t tested it yet.
First of all i want to check if what is selected in the drop-boxes.
`If($_POST[telefon]=”empty”){$tel=””}
else{$tel=”WHERE telefon =’ “}`
after this i can concatenate the $tel string with the $_POST['telefon'] string.
$query_tel=$tel.$_POST['telefon']." ' ";
Final query string would look like this $query="SELECT * table ".$query_telefon." ,".$query_ziua....(and so on)
Of course i have to be very careful with the query that will result, for missing commas, apostrophes and so on. But i guess it’s the simplest way.
UPDATED
ASSUMPTION: the point here is you want reduce code in relation with number of query!
PREMISE: the use of
switchorand/ifare both valid approach anyway!try this: