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?