Building a Dynamic Where Clause
Problem - I wish to use a filter within the results page - i.e. Dropdown List - to allow selection of products by price range. Once the search has been made or result page loaded.
<?php
if (isset($_GET["ProductOccasionID"]) && isset($_GET["Search"])) {
if ($WADbSearch1->whereClause != "") {
$WADbSearch1->whereClause .= " AND ";
}
$WADbSearch1->whereClause .= "ProductID IN (SELECT ProductID FROM productoccasions WHERE (OccasionID = ".implode($_GET["ProductOccasionID"]," OR OccasionID = ")."))";
$_SESSION["WADbSearch1_Admin_Products_Results"]=$WADbSearch1->whereClause;
}
?>
If I manually alter the line as follows:-
$WADbSearch1->whereClause .= " AND (ProductPrice >= 10.00) & (ProductPrice <= 25.00) AND ProductID IN (SELECT ProductID FROM productoccasions WHERE (OccasionID = ".implode($_GET["ProductOccasionID"]," OR OccasionID = ")."))";
The data is selected as requested. However, I need this to be dynamic for the filter to work properly.
I am trying to get the whereclause to include a $price_query string. Something like
$WADbSearch1->whereClause .= $price_query . "ProductID IN (SELECT ProductID FROM productoccasions WHERE (OccasionID = ".implode($_GET["ProductOccasionID"]," OR OccasionID = ")."))";
Whereby $price_query holds the text element " AND (ProductPrice >= 10.00) & (ProductPrice <= 25.00) AND " and gets appended in front of the Original whereClause text ProductID IN (SELECT ProductID FROM productoccasions WHERE (OccasionID = ".implode($_GET["ProductOccasionID"]," OR OccasionID = ")."))
But the Text held in $price_query is not being appended to my whereClause search. Any help would be welcome.