I'm trying to create a search page that will filter the database to show what the user wants.
The page I have coded is http://everglademedia.com/clients/directco...rch_orders.html - they check the box next to the field(s) they want to search by.
The problem is, how can I make a query, because there are so many combinations!
A user can select to search by status and origin_state, user can select to search by status and destination_state, user can select to search by status and transporter, user can select to search by status alone, user can select to search by status and pickup_date, and user can select to search by status and delivery_date. All of that is just for status!
What I have so far is:
CODE
if ( $_POST['searchby_status'] == 'on' )
{
$status = " status = '" . $_POST['status'] . "'";
}
if ( $_POST['searchby_origin_state'] == 'on' )
{
$origin_state = " origin_state = '" . $_POST['origin_state'] . "'";
}
if ( $_POST['searchby_destination_state'] == 'on' )
{
$destination_state = " destination_state = '" . $_POST['destination_state'] . "'";
}
$query = "SELECT * FROM direct_orders WHERE " . $status . "
{
$status = " status = '" . $_POST['status'] . "'";
}
if ( $_POST['searchby_origin_state'] == 'on' )
{
$origin_state = " origin_state = '" . $_POST['origin_state'] . "'";
}
if ( $_POST['searchby_destination_state'] == 'on' )
{
$destination_state = " destination_state = '" . $_POST['destination_state'] . "'";
}
$query = "SELECT * FROM direct_orders WHERE " . $status . "
But I'm not sure how I'd make use of it, because of the different combinations, I would have to know when to use an AND in the query. Any ideas?
