close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Search Behavior WHERE question.

Thread begun 2/13/2011 9:32 pm by troyd | Last modified 2/15/2011 2:34 am by Dave Buchholz | 4441 views | 14 replies |

troyd

Search Behavior WHERE question.

Is it possible to set the SQL or maybe a session to include a keyword before a search is performed?
What I am needing is for the page to show all records with a particular criteria when the user first visits. Then change if a search is performed.

We have a column in the table called 'status'. There are 3 possible values. 0, 1, 2 which represent "Available", "On Hold" and "Sold".
We need just the "Available" records to show when they first visit the page and don't do anything. But if they click the link for "Sold", then all the records marked "Sold" will show.

The search behavior is already in place and working just fine. I created a URL variable called "Status" and used echo $_GET['Status']; in the search behavior's value for comparison.

The link that triggers the "Sold" looks like this somepage.php?Status=2, and so on.

So I have tried to mess with the "Where" statement in the search behavior but with no luck. Should I be doing this in the SQL statement first?

I can provide more of my code if needed.

Thanks,
TroyD

Sign in to reply to this post

Dave BuchholzBeta Tester

If you open the DataAssist Search Server Behaviour



You can see there is a default where clause option



The help docs say

  Default WHERE clause: The default where clause used if the session variable is not set and the user has accessed the current page without passing the appropriate trigger to run the server behavior. Here are some examples for returning all or no records:

To default to no records displayed:
WHERE 0 <> 0

To default to all records displayed:
WHERE 0 = 0  



So although I have never personally used this option I would say that you could use it to achieve the result you are looking for

Sign in to reply to this post

troyd

Thanks Dave,

As always, your quick to help.

How are you setting that trigger? That might be my first issue because I was using "before page load". I've tried using the session in the dropdown but I don't get the $_POST like I see in your screenshot.

I tried hand coding it like this. But without any Default WHERE. So I'm not sure if it's correct or not. Because adding anything in the WHERE give me a syntax error.

php:
$WADbSearch1_DefaultWhere = "";

if (!session_id()) session_start();
if ((isset($_POST['WADbSearch1_test'])) && ($_POST['WADbSearch1_test'] != "")) {


(I might be missing some () in the above. Still learning that part.)

I never can get the default where to work in the WA Search behavior. I always have to leave it blank. Maybe it's my combination of the wrong trigger with the wrong WHERE default.

Again, thanks for any help,
TroyD

Sign in to reply to this post

Jason ByrnesWebAssist

the default where clause is only used if 2 conditions are met:
1) A prior search has not been completed in the current browsing session
2) The trigger is not met

When you do a search, the search is stored in a session variable, the search in the session variable will be used if it exists and the trigger is not met.

In your case, using the Before Page Load trigger will cause the search code to run any time the page is loaded.


also in your case, the search is using the GET Method, not the POST methods, so the trigger Dave is using will not be valid.

On the bindings panel, make sure there is a URL Variable section that contains a binding for the Status querystring.


then in Data Assist Search, click the lightning bolt next to Trigger and select the Status URL Variable.


this way the search code will only trigger if that variable is present.


then set the default where to:
Status=2

Sign in to reply to this post

troyd

Thanks Jason,

Yes, I have tried that. And just tried it again. I do have a URL variable set in the bindings called Status. And I have a column in the table called status.

I get this error every time I include any type of WHERE...
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Status=2 ORDER BY status ASC LIMIT 0, 100' at line 1"

It doesn't matter if I have Status=2, Status=0, 0 <> 0 or 0=0, I still get a similar error.

Maybe I have something else set wrong. I totally removed the search behavior and started from scratch. Here's the top half of the search behavior. (if you need more, let me know.)

php:
$WADbSearch1_DefaultWhere = "Status=2";

if (!session_id()) session_start();
if ((isset($_GET['Status']) && $_GET['Status'] != "")) {
  $WADbSearch1 = new FilterDef;
  $WADbSearch1->initializeQueryBuilder("MYSQL","1");
  //keyword array declarations
  $KeyArr1 = array("status");

  //comparison list additions
  $WADbSearch1->keywordComparison($KeyArr1,"".$_GET['Status']  ."","AND","=",",%20","%20","%22","%22",0);

  //save the query in a session variable
  if (1 == 1) {
    $_SESSION["WADbSearch1_test"]=$WADbSearch1->whereClause;
  }
}
else     {
  $WADbSearch1 = new FilterDef;
  $WADbSearch1->initializeQueryBuilder("MYSQL","1");
  //get the filter definition from a session variable
  if (1 == 1)     {
    if (isset($_SESSION["WADbSearch1_test"]) && $_SESSION["WADbSearch1_test"] != "")     {



If I append the url with ?Status=0 or ?Status=1 etc. it works just fine and the error goes away. AND!! I can even go back to the original url and refresh getting no error but only getting the results from the last link clicked. Telling me that the session is not being set in the first visit to the page.

I have the search behavior at the top of the page with the require_once("WADbSearch/HelperPHP.php"); above that.

Any thoughts? What do I have set wrong? Do I need some way of setting this session differently than I have now?

Thanks,
TroyD

Sign in to reply to this post

Jason ByrnesWebAssist

try using:
WHERE Status=2


as the default where clause.

Sign in to reply to this post

troyd

Jason,

That gives me a similar error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ANDStatus=0 ORDER BY status ASC LIMIT 0, 100' at line 1

when using

php:
$WADbSearch1_DefaultWhere = "WHERE Status=0";



Does it matter how I have the Search Parameter set? Maybe that's my problem.
*Note-the column 'status' is an integer.

This is what I have:

Separator: AND
Column: status
Column Type: -I tried both Number/Boolean and Text as the column type. That didn't seem to matter.-
Filter Type: Keyword
Value: <?php echo $_GET['Status']; ?>
Keyword AND: ,
Keyword OR: -empty-

Thanks,
TroyD

Sign in to reply to this post

Jason ByrnesWebAssist

OK, try leaving the WHERE off, but include a space at the beginning:

php:
$WADbSearch1_DefaultWhere = " Status=0";





if you are still having a problem, send a copy of the page in a zip archive so i can see the complete page code.

Sign in to reply to this post

troyd

Nope, that didn't work either. I've attached a zipped copy of the page (unformatted).

Not sure where I went wrong. Let me know if you see anything.

Thanks,
TroyD

Sign in to reply to this post

Jason ByrnesWebAssist

change this line:

php:
$rsAvailableHH = mysql_query($query_rsAvailableHH, $dbCMS) or die(mysql_error());



to:

php:
$rsAvailableHH = mysql_query($query_rsAvailableHH, $dbCMS) or die($query_rsAvailableHH."<br />".mysql_error());



then go back to using:
$WADbSearch1_DefaultWhere = " AND status=0";

this will write the full query to the screen along with the error to give us some more information.

Sign in to reply to this post
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...