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

rating

Incorrect search results if searching by date range and any other criteria

Thread began 7/01/2011 8:31 am by YellowCircleWeb | Last modified 7/01/2011 3:18 pm by Jason Byrnes | 1068 views | 5 replies |

YellowCircleWeb

Incorrect search results if searching by date range and any other criteria

Hi,

I've created a search page that searches records by various criteria and is mostly working fine. However, one of the search criteria is a date range (I'm using the WA Datepicker control for these fields).

If I search for records between 2 specific dates I get the correct results returned. If I search for records using search criteria and not entering any dates I get correct results. If I search for records using a date range and then any other criteria I get all the records returned, not just the correct ones. I've been trying to solve this for all day and so far cannot get it working. It's like the page is ignoring the unique value I also tell it to check for (ACCOUNT_REF) when I use dates and other criteria.

I've attached the two files involved and wonder if anyone can point me in the right direction as to why I'm getting incorrect results.

Attached Files
order-search-results.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the first step to troubleshooting search results is to write the SQL statement being generated to the page. add the following code just after the <body> tag to write the sql statement:

php:
SQL: <?php echo($query_rsGetOrderSummaryForSearch); ?><br />




i can see in the Search Server behavior though that you have mixed some "AND" criteria and some "OR" criteria.


by mixing the type like this you are causing the unexpected results.

Sign in to reply to this post

YellowCircleWeb

Hi Jason,

I need to have both AND and OR type search results included. My client wanted the search to allow users to enter multiple criteria and not be restricted to all AND type search results e.g. if they incorrectly entered one piece of data, but entered another correctly it would still find a match on the correctly entered field value.

I built a safeguard in to retrieve results only for the currently logged in user by specifying an AND search on the ACCOUNT_REF value, which is a field in the database matched to a session variable that gets set once the user has logged in. However, this seems to be being ignored when using Date range and any other criteria.

I did as you suggested and wrote the SQL query to the page and got the following:

SQL: SELECT * FROM stg_ordersummary WHERE (ORDER_DATE >= "2011-07-01 00:00:00") AND (ORDER_DATE <= "2011-07-01 23:59:59") OR ((CUST_ORDER_NUMBER = '13735')) AND ((ACCOUNT_REF = 'BWEUROPE')) ORDER BY ORDER_DATE DESC

However, records were returned that were outside of the specified date range. Is this down to the fact that my SQL is only applying the AND operator to the dates and then saying - ok no match there, but there's this OR value on the CUST_ORDER_NUMBER field and I've found records that match that field - so that's what's displaying??

Still puzzled as to why I'm getting records returned for other users though who I'm not logged in as????

Sign in to reply to this post

Jason ByrnesWebAssist

  Is this down to the fact that my SQL is only applying the AND operator to the dates and then saying - ok no match there, but there's this OR value on the CUST_ORDER_NUMBER field and I've found records that match that field - so that's what's displaying??  



yes, exactly, when you mix criteria "AND" and "OR", any matches are included in the result set.

the ACCOUNT_REF value is being ignored because there are other records between the dates specified.

Sign in to reply to this post

YellowCircleWeb

Thank you for your help Jason.
I've changed all of the search criteria to use the AND operator and it's now working. I also applied a filter to the recordset before any search queries were performed so that only records for the currently logged in account were used in the records being searched. This has fixed the issue of records for other accounts being returned now.

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear it is working.

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