I have a form that allows for several different search option inputs. Such as text boxs and drop downs. As of now I search by waiting for a search REQUEST and then seeing if there is any character input in the various text boxes or what drop down option is selected.
Basically it is branches of conditional logic using if statements then modifying the sql statement depending what is chosen. How can I make it to where it supports single options or several linked together?
Example of current condititional logic
$sql = "SELECT ";
if(strlen($_REQUEST['Option1']) > 0) {
$sql .= "* FROM Table Where Option1 = {$_REQUEST['Option1']} ";
}
if(strlen($_REQUEST['Option 2']) > 0) {
$sql .= "* From Table Where Option2 >= {$_REQUEST['Option2']}";
I understand I need to use AND in the sql query. I tried to do it wit开发者_StackOverflow中文版h arrays of options then looping through depending on the boolean state but it didn't work
Put the where clauses in an array then do an implode with OR or AND:
$sql .= implode(" AND ", $whereArray);
精彩评论