First of let me explain my project. In my project i have many search parameters such as First Name , Last Name , Address , Valid ID. These are the parameters i am taking from users to search the database. I am giving the users the flexibility to search the database with 4 parameters or 3 or 2 or 1 depending on the user. Increasing the search parameters decreases the margin of the search. Currently the way i search the database is by checking each parameters. I am having all the possibility or combination of all 4 parameters.
4 combinations of using 1 parameter
6 combination of using 2 parameters
4 combinations of using 3 parameter
1 for using 4 parameters
giving me a total of 15 if statements. Is there a cleaner more short way to make it?I am asking this because now i am working with making 7 parameters and the combinations is really big.
In code it would look like this
if(!empty(fname)){}
else if(!empty(lname)){}
else if(!empty(address)){}
else if(!empty(vid)){}
else if(!empty(fname) && !empty(lname)){}
else if(!empty(fname) && !empty(address)){}
else if(!empty(fname) && !empty(vid)){}
else if(!empty(address) && !empty(lname)){}
else if(!empty(vid) && !empty(lname)){}
else if(!empty(adress) && !empty(vid)){}
else if(!empty(fname) && !empty(lname) && !empty(address)){}
else if(!empty(fname) && !empty(lname) && !empty(vid)){}
else if(!empty(fname) && !empty(add) && !empty(vid)){}
else if(!empty(lname) && !empty(add) && !empty(vid)){}
else if(!empty(fname) && !empty(add) && !empty(vid) && !empty(lname)){}
7 parameter = 1 combination ;6p = 7c;5p = 21c;4p = 35c;3p = 35c;2p = 21c;1p = 7c;total of127 combinationsthen i would have to make 127 if statements