Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.