Solarpitch Posted July 10, 2009 Share Posted July 10, 2009 Hey, I'm trying to figure out how I can create a search query when the user has to select from multiple select boxes to adjust their search parameters. For example, say I have... EMAIL ADDRESS: (select) -Any -Customers with email address -Customers without email address PHONE NUMBER (select) -Any -Customers with a phones number -Customers with no phone number SALES PERIOD (User enters a sales to and from date) 14/02/09 - 03/06/09 COUNTRY (select) -Ireland -UK -United States So say I need to see what was check so I can run a query like: SELECT * FROM CLIENTS WHERE email_address != "" AND phone_number = "" AND sales_to > '140209' AND sales_from < '030609' AND country = "Ireland" How can I run the checks to construct the query? Quote Link to comment https://forums.phpfreaks.com/topic/165481-creating-a-search-from-multiple-parameters-and-select-boxes/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 <?php $select = 'SELECT * FROM clients'; $where = ''; if (!empty($_POST['email_address'])) { $emailAddress = $_POST['email_address']; // don't forget to validate and filter $where .= " email_address = '$emailAddress' OR email_address LIKE \'%$emailAddress%\'"; } if (!empty($_POST['phone_number'])) { .. $select .= "WHERE $where"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165481-creating-a-search-from-multiple-parameters-and-select-boxes/#findComment-872787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.