close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

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 Ray Borduin | 771 views | 11 replies |

Dragan

Search filter: SQL syntax and WebAssist application

I need your advice how to create a search field to be able to filter only those advertisements that
a) were posted in the last X-number of days, and
b) which expiry date is greater than today’s date.

The search filed is a Menu/List drop-down box with alternatives 1, 3, 7, 14, 21 and 28 days. I tried the below SQL statement
SELECT ads.updated, ads.expires
FROM ads
WHERE (DateDiff("d",updated,Date())<=10) AND expires>Date();

Number 10 is just for testing purposes. It will be dynamic, replaced with the input from the above Menu/List box. However, the SQL is not working in the Recordset Query Builder. I get message
“You have an error in your SQL syntax; check the manual that coresponds to MariaDB server version for the right syntax to use near "))<=10) AND expires>Date()" at line 1.”

Even if SQL was working, I would not know what to do with it. I need from you detailed instructions on how to create such a search filter. Please help me, as I do not have other options to solve the problem.

Sign in to reply to this post

Ray BorduinWebAssist

Your DateDiff syntax appears incorrect. I think it would be:

DATE_ADD(ads.updated, INTERVAL 10 DAY) > Date()

Once you have it working, you can just replace the 10 with a sql parameter and get the value from your search field.

Sign in to reply to this post
Did this help? Tips are appreciated...

Dragan

Thank you Ray. I have sorted out the SQL syntax (SELECT ads.updated, ads.expires FROM ads WHERE DATE_ADD(ads.updated, INTERVAL 10 DAY) > CURDATE() AND expires>CURDATE());) It is working in recordset advanced panel.

However, I do not know what to do with it.

I created search and result pages. I added recordsets on both pages. I applied search wizard to the result page. But I do not know how to insert dynamic filed for INTERVAL 10 DAY, instead of number 10, like INTERVAL [dynamic filed] DAY.

How could I get the value from the search field. Could you please help me?

Sign in to reply to this post

Ray BorduinWebAssist

You should probably save the value from the search field into the session. That way it will be maintained when they browse from page to page or click on the details and return to the results.

Then you can add a sql parameter to the Recordset. Take a look at the details page created by DataBridge to see what a sql parameter looks like.

Sign in to reply to this post
Did this help? Tips are appreciated...

Dragan

Could you please tell me how to
1. "...save the value from the search field into the session?" and
2. Which section from WebAssist should I use, and
3. What should I do when I create a session? and
4. How should I call the session on the next/record page?

Sign in to reply to this post

Ray BorduinWebAssist

1) Use the server behavior: Webasist->Cookies->Set Session Value
2) See #1
3) See #1
4) Once you add the session variable it should show in the Bindings panel to use on your page

Sign in to reply to this post
Did this help? Tips are appreciated...

Dragan

Thank Ray for you reply, but it does not help me as I absolutely do not know
1. What fields to chose from the Set Session Value panel, and what to put in the fields;
2. Where the session should be on search, or on results page or on both?
3. What to do with the session once I create the session?
4. How should I get the chosen value from Menu/List/Drop-down box on the search page into SQL statement on the result page?
Could you please provide me step-by-step details of what I need to do?

Sign in to reply to this post

Ray BorduinWebAssist

An HTML form works by submitting form elements from one page to another, or to itself. The page that receives the form field values is the page specified as the action of the form.

In most search forms you use method="get" in the form so that the search fields appear in the url. The reason why is that it allows you to send the search results to someone else, which you can't do with a form POST.

If you want to make a submitted value more permanent, you use the SESSION.

In your case, you want to save the value of the number of days to show. You want to use the session so that if the user navigates to the next page in the result-set, the value is maintained.

Since you are saving the value from the submitted form, it has to be on the page specified as the action of that form, because that is the only page the receives the value. So, your results page in this case.

Once you create the session variable it is available to use on any other pages after that page. It is a persistent value. In your case you can use it in your sql_parameter to add the value to your recordset.

So, the value is submitted on the search page and sent to the results page. The results page saves the value into the session so it will be persistent, and then uses the session to set the value in the recordset.

If you want to schedule a premier support ticket, then I could go through all of this with you in a screen sharing session and show you how to do it, but it shouldn't be too difficult to do.

Have you tried? How far do you get? Instead of asking 4 questions, just ask 1 question and concentrate on the step you are stuck on. Then I can answer that one question more thoroughly and help you get through it before moving on to the next.

I don't know your understanding of HTML, PHP, MySQL, or web development in general. I try to answer your questions but it can get confusing when I'm answering multiple questions at once. Take it slow and you can get through it. If you want it done quickly, then I'd suggest premier support.

Sign in to reply to this post
Did this help? Tips are appreciated...

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?

Sign in to reply to this post

Ray BorduinWebAssist

I'd have to debug it. Can you give me FTP access so I can do some testing?

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

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