close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Building a Dynamic Where Clause

Thread began 8/13/2010 10:47 am by dnys04173367569 | Last modified 8/23/2010 11:30 am by Jason Byrnes | 784 views | 3 replies |

dnys04173367569

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.

Sign in to reply to this post

Jason ByrnesWebAssist

check the code order.


make sure that the code that creates the $price_query variable is before the code that uses it.

If it is not being included, I would suspect that it is not being created before the $WADbSearch1->whereClause .= $price_query line.

Sign in to reply to this post

dnys04173367569

I have corrected this and have a $price_query variable that should change when a filter button is pressed.

However, any changes to the $price_query is not happening.

I believe that the orginal whereClause gets set, when the page initially loads and that will include what is initially held in the $price_query variable, but when the page is refreshed by an update to the price filter the where clause is not getting updated with the change.

$WADbSearch1->whereClause .= $price_query . "ProductID IN (SELECT ProductID FROM productoccasions WHERE (OccasionID = ".implode($_GET["ProductOccasionID"]," OR OccasionID = ")."))";

Is there anyway I can force the whereClause to update and accept the change of the $price_query variable.

The variable is to be selected by a dropdown box once the page is loaded and then the customer can selected to show items based on a number of price options eg. $10 to $50 or $50 to $100.

I have tested the filter to check that $price_query does change when the filter button is selected by echoing the varaible within the same page, however the whereClause is not changeing based on the change to the variable, which leads me to believe that the whereClause is not being updated with the refresh of the page.

Any help would be greatly appreciated.

Sign in to reply to this post

Jason ByrnesWebAssist

the data assist search behavior will only be applied if there is a search query string variable, make sure that the code to reload the page includes a search querystring variable:

products_Results.php?search=search

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...