Jump to content

Creating a search from multiple parameters and select boxes.


Solarpitch

Recommended Posts

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?

<?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";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.