930rcr Posted April 9, 2014 Share Posted April 9, 2014 Hi, My first post here as I am exploring the php world. I am building a database mysql database filter and have run into a roadblock. I have built a form that has multiple input options. I would like to have the form return all table information if all of the inputs are left blank. I would also like to have the table filter via any combination of responses the user inputs I have been able to write a query in myphpadmin that returns the proper values, but have been unable to replicate it in the php environment. I believe it ultimately has to do with my variable definitions, as I am trying to understand how to allow blank input sections: if($_GET) { //Define Variables $firstname=""; if(!empty($firstname = FALSE)); elseif(isset($_GET['first'])){ $firstname = $_GET['first']; } $lastname=""; if(!empty($lastname = FALSE)); elseif(isset($_GET['last'])){ $lastname = $_GET['last']; } $bibsearch=""; if(!empty($bibsearch = FALSE)); elseif(isset($_GET['bib'])){ $bibsearch = $_GET['bib']; } $divsearch=""; if(!empty($division = FALSE)); elseif(isset($_GET['division'])){ $divsearch = $_GET['division']; } $sex=""; if(!empty($sex = FALSE)); elseif(isset($_GET['sex'])){ $sex = $_GET['sex']; } the query is: $query = "SELECT * FROM `table 1` WHERE ( `first` = '" . $firstname . "' || `last` = '" . $lastname . "' || `bib` = '" . $bibsearch . "' || `division` = '" . $divsearch . "' || `sex` = '" . $sex . "' )"; Any insight would be quite helpful. Thanks for your time. Best, Link to comment https://forums.phpfreaks.com/topic/287655-multiple-filters/ Share on other sites More sharing options...
cyberRobot Posted April 10, 2014 Share Posted April 10, 2014 There are quite a few syntax errors in the PHP code. Are you getting any errors? For what it's worth, the if statements should look more like this: if(isset($_GET['first'])) { $firstname = $_GET['first']; } else { $firstname = ''; } You could also consider using the Ternary Operator: if($_GET) { //Define Variables $firstname = (isset($_GET['first'])) ? $_GET['first'] : ''; $lastname = (isset($_GET['last'])) ? $_GET['last'] : ''; $bibsearch = (isset($_GET['bib'])) ? $_GET['bib'] : ''; $divsearch = (isset($_GET['division'])) ? $_GET['division'] : ''; $sex = (isset($_GET['sex'])) ? $_GET['sex'] : ''; } Link to comment https://forums.phpfreaks.com/topic/287655-multiple-filters/#findComment-1475669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.