I am not sure exactly how to explain this so bare with me. I have a conditional query search and want some advice on the best way to approach this. I don’t think the way I am doing it is the best way so your help would be appreciated. Thanks again for your help.
Here is what I am attempting. I want to pull some conditional results based on the number that is pulled. Here is a basic example…
[code=php]
$query = “SELECT * FROM $tbname WHERE option1=’$option1′;
$result = mysql_query($query, $connect);
$num = mysql_num_rows($result);
$highNum = 6;
if($num > $highNum){
$query = “SELECT * FROM $tbname WHERE option1=’$option1′ AND option2=’$opiont2′”;
$result = mysql_query($query, $connect);
$num = mysql_num_rows($result);
} else if($num > $highNum) {
$query = “SELECT * FROM $tbname WHERE option1=’$option1′ AND option2=’$opiont2′ AND option3=’$option3′”;
$result = mysql_query($query, $connect);
$num = mysql_num_rows($result);
} else if($num > $highNum) {
// and so on until the search query comes below the number 6
}
The trick for me is that I want to add more options down the road and for the true application it can result in a lot of if/else statements. Not only can this become time consuming, it’s a lot of code to go back and edit later. I don’t mind doing the work but I would also like to try and keep the code as efficient and quick as possible.
Any suggestions on how to improve this. I hope my explanation is clear and understandable. Thanks again for the help.