I try to create a selection page, where different query are made, depending on selected checkboxes, and textboxes.
It works for most the part but I a selection between zipcode ranges and year of birth range (between nbs_zip and nbs_zip2 and between nbs_contact_year and nbs_contact_year2).
It works when I have for example nbs_zip and nbs_zip2 filled with a zipcode and only nbs_contact_year filled (not second nbs_contact_year2).
But I can't get the query to work when I enter in both zipcode1 and 2 and year1 and 2 (second elseif).
Here is part of the code I use (it has multiple ways for the selection).
if(!empty($_POST['nbs_zip2']))
{
$sql_query = "SELECT * "
. " FROM nbs_contacts JOIN nbs_events "
. " ON nbs_contacts.nbs_contact_id = nbs_events.nbs_events_id "
. " WHERE nbs_relativeto LIKE '%$nbs_relativeto%' AND nbs_contact_year LIKE '%$nbs_contact_year%' AND nbs_year LIKE '%$nbs_year%' ";
{
$sql_query .= " AND nbs_zip BETWEEN $nbs_zip AND $nbs_zip2 ";
}
$sql_query .= " $sqlAND";
}
elseif(!empty($_POST['nbs_contact_year2']))
{
$sql_query = "SELECT * "
. " FROM nbs_contacts JOIN nbs_events "
. " ON nbs_contacts.nbs_contact_id = nbs_events.nbs_events_id "
. " WHERE nbs_relativeto LIKE '%$nbs_relativeto%' AND nbs_zip LIKE '%$nbs_zip%' AND nbs_year LIKE '%$nbs_year%' ";
{
$sql_query .= " AND nbs_contact_year BETWEEN $nbs_contact_year AND $nbs_contact_year2 ";
}
$sql_query .= " $sqlAND";
}
elseif(!empty($_POST['nbs_contact_year2']) && !empty($_POST['nbs_zip2']))
{
$sql_query = "SELECT * "
. " FROM nbs_contacts JOIN nbs_events "
. " ON nbs_contacts.nbs_contact_id = nbs_events.nbs_events_id "
. " WHERE nbs_relativeto LIKE '%$nbs_relativeto%' AND nbs_zip LIKE '%$nbs_zip%' AND nbs_year LIKE '%$nbs_year%' ";
{
$sql_query .= " AND nbs_contact_year BETWEEN $nbs_contact_year AND $nbs_contact_year2 ";
}
{
$sql_query .= " AND nbs_zip BETWEEN $nbs_zip AND $nbs_zip2 ";
}
$sql_query .= " $sqlAND";
}
else
{
$sql_query = "SELECT * "
. " FROM nbs_contacts JOIN nbs_events "
. " ON nbs_contacts.nbs_contact_id = nbs_events.nbs_events_id "
. " WHERE nbs_relativeto LIKE '%$nbs_relativeto%' AND nbs_contact_year LIKE '%$nbs_contact_year%' AND nbs_zip LIKE '%$nbs_zip%' AND nbs_year LIKE '%$nbs_year%' $sqlAND";
}
Please need help soon!
Thanks