close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Search filter: SQL syntax and WebAssist application

Thread began 3/23/2021 9:29 pm by Dragan | Last modified 3/30/2021 9:29 am by Dragan | 74 views | 11 replies

Dragan

Thank you Ray for your reply. I have very basic knowledge of PHP and SQL and no knowledge of Sessions. I am developing this website as a need to create a business, which would give me funds for living. I cannot afford to outsource development of my website. That is why I bought Data Bridge 2.

I have created a search page which has 5 search fields. The 4 of them are working well. The last, 5th one, is the one which users will use to select number of days since advertisement was posted/updated.

Whilst developing the 5th field, I worked on a separate page, which contains only one search filed, a dropdown box with numbers, 1,3,5,7,14,21,28.

Yesterday, I managed to get that search to work on that separate page. On that page I have the following script:

SCRIPT 1:
<?php
@session_start();
if ((((isset($_POST["Updated"]))?$_POST["Updated"]:"") != "")) {
$_SESSION["sesUpdated"] = "".((isset($_POST["Updated"]))?$_POST["Updated"]:"") ."";
}
?>
<?php
$interval = (int)$_SESSION['sesUpdated'];
$rsAds = new WA_MySQLi_RS("rsAds",$conAdPlus,0);
$rsAds->setQuery("SELECT ads.updated, ads.expires FROM ads WHERE DATE_ADD(ads.updated, INTERVAL $interval DAY) > CURDATE() AND ads.expires>CURDATE()");
$rsAds->execute();
?>
<?php
$searchrsAds_WADbSearch1 = new WA_MySQLi_Search("rsAds","");
if ((isset($_POST["WADbSearch1"])) && ($_POST["WADbSearch1"] != "")) {
$searchrsAds_WADbSearch1->clearSearch();
$searchrsAds_WADbSearch1->setSearch(array("type"=>"List", "comparison"=>"=", "join"=>"AND"), array("updated"), "d", "Updated");
}
?>

Now, when I apply these principles to the page where I have 4 other search fields, the search does not work. No data, or partial/incorrect data is retrieved. On that page the codes are:

SCRIPT 2:
<?php
@session_start();
if ((((isset($_POST["Updated"]))?$_POST["Updated"]:"") != "")) {
$_SESSION["sesUpdated"] = "".((isset($_POST["Updated"]))?$_POST["Updated"]:"") ."";
}
?>
<?php
$searchrsAds_WADbSearch1 = new WA_MySQLi_Search("rsAds","1=0");
if ((isset($_POST["WADbSearch1"])) && ($_POST["WADbSearch1"] != "")) {
$searchrsAds_WADbSearch1->clearSearch();
$searchrsAds_WADbSearch1->setSearch(array("type"=>"Edit", "comparison"=>"=", "join"=>"AND"), array("ad_id"), "d", "AdsID");
$searchrsAds_WADbSearch1->setSearch(array("type"=>"Key", "comparison"=>"Includes", "join"=>"AND", "and"=>", ", "or"=>" ", "start_encap"=>"\"", "end_encap"=>"\""), array("ad_text"), "s", "".((isset($_POST["AdsKeywords"]))?$_POST["AdsKeywords"]:"") ."");
$searchrsAds_WADbSearch1->setSearch(array("type"=>"List", "comparison"=>"=", "join"=>"AND"), array("buy_sell"), "s", "SellBuy");
$searchrsAds_WADbSearch1->setSearch(array("type"=>"List", "comparison"=>"=", "join"=>"AND"), array("ad_category"), "s", "Category");
$searchrsAds_WADbSearch1->setSearch(array("type"=>"List", "comparison"=>"=", "join"=>"AND"), array("updated"), "t", "Updated");
}
?>
<?php
$interval = (int)$_SESSION['sesUpdated'];
$rsAds = new WA_MySQLi_RS("rsAds",$conAdPlus,1);
$rsAds->setQuery("SELECT blist.business_name, blist.business_category, blist.city, ads.ad_id, ads.updated, ads.expires, ads.ad_category, ads.buy_sell, ads.ad_text, ads.contact_name, ads.contact_phone, ads.contact_email, ads.location FROM blist INNER JOIN ads ON blist.blist_id = ads.blist_id
WHERE DATE_ADD(ads.updated, INTERVAL $interval DAY) > CURDATE() AND ads.expires>CURDATE()
AND ads.ad_id = ads.ad_id");
$rsAds->execute();
?>

When I test the entire SQL statement (as per SCRIPT 2) in WebAssist advanced Recordset panel, ($interval replaced with a number) the search is working. That means the SQL statement is correct.

Also, when I test SCRIPT 1, on its own search and result pages, without 4 other search fields, the script is working.

Also, when I use SCRIPT 2 without $interval = (int)$_SESSION['sesUpdated']; and DATE_ADD(ads.updated, INTERVAL $interval DAY) > CURDATE() AND ads.expires>CURDATE(), the search is working, for all 4 fields.

However, when I add $interval = (int)$_SESSION['sesUpdated']; and DATE_ADD(ads.updated, INTERVAL $interval DAY) > CURDATE() AND ads.expires>CURDATE(), to the result page with 5 search fields, (as per SCRIPT 2), I get either “No results found” or partial/incorrect results.

Sometimes I also get message, “Warning: Undefined array key "sesUpdated" in C:\xampp\htdocs\adplus\adsresults.php on line 23,” despite that Session script is on the page (see SCRIPTS 1 and 2). That means sometimes Session is recognised, sometimes not. I have noticed that the error message does not happen when I come to the search page with 5 search fields, after I use the search and result pages that works, those with only one field, on which I originally created Session.

What shell I do to get the search/SQL to work?

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