close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Search not filtering after I add additional "Where" clause in the recordset

Thread began 1/04/2015 8:10 pm by Blikbrein | Last modified 1/07/2015 10:36 am by Jason Byrnes | 1721 views | 6 replies |

Blikbrein

Search not filtering after I add additional "Where" clause in the recordset

I have a page with payments and charges that is filtered by begin date and end date. I do not want to show any zero values in the filtered report and therefor I have added a Where in the recordset:

WHERE PaymentDebit > 0 OR PaymentCredit > 0

Without the 'OR PaymentCredit > 0' Date filtering works but after adding it all records are shown and there is no filtering.

I've attached the page for you to inspect. The result must be that records are filtered according to begin and end date and that items with a 0 in PaymentDebit AND 0 in PaymentCredit should not be shown which would be a 0 value record.

Attached Files
Transaction_results.php
Sign in to reply to this post

Jason ByrnesWebAssist

change the OR:
WHERE PaymentDebit > 0 OR PaymentCredit > 0

to use AND instead:
WHERE PaymentDebit > 0 AND PaymentCredit > 0

Sign in to reply to this post

Blikbrein

Thanks but in this case OR is needed since all debits have 0 credit values and all Credits have 0 debit values which means every entry will have either a 0 in the debit field or a 0 in the credit field. No record wil have a debit AND credit > 0. This needs to be OR, but as I said the Search behaviour then shows all the records in the query instead of filtering them.

Sign in to reply to this post

Jason ByrnesWebAssist

The recordset code is duplicated.

change lines 135 - 164:

<?php
$maxRows_WADAPayments = 1000;
$pageNum_WADAPayments = 0;
if (isset($_GET['pageNum_WADAPayments'])) {
$pageNum_WADAPayments = $_GET['pageNum_WADAPayments'];
}
$startRow_WADAPayments = $pageNum_WADAPayments * $maxRows_WADAPayments;

mysql_select_db($database_anna, $anna);
$query_WADAPayments = "SELECT PaymentsID, `Users`.`UserFirstName` AS Users_UserFirstName, Users.UserSurname, `ContractTracking`.`PackageID` AS ContractTracking_PackageID, PaymentDate, PaymentDocno, PaymentDebit, PaymentCredit FROM Payments LEFT JOIN Users ON Users.UserID = Payments.PaymentClientID LEFT JOIN ContractTracking ON ContractTracking.ContractID = Payments.PaymentContractTrackingID WHERE PaymentDebit > 0 OR PaymentCredit > 0 ORDER BY Users.UserSurname ASC, `Users`.`UserFirstName` ASC, PaymentDate ASC";
setQueryBuilderSource($query_WADAPayments,$WADbSearch1,false);
$query_limit_WADAPayments = sprintf("%s LIMIT %d, %d", $query_WADAPayments, $startRow_WADAPayments, $maxRows_WADAPayments);
$WADAPayments = mysql_query($query_limit_WADAPayments, $anna) or die(mysql_error());
$row_WADAPayments = mysql_fetch_assoc($WADAPayments);

if (isset($_GET['totalRows_WADAPayments'])) {
$totalRows_WADAPayments = $_GET['totalRows_WADAPayments'];
} else {
$all_WADAPayments = mysql_query($query_WADAPayments, $anna);
$totalRows_WADAPayments = mysql_num_rows($all_WADAPayments);
}
$totalPages_WADAPayments = ceil($totalRows_WADAPayments/$maxRows_WADAPayments)-1;

mysql_select_db($database_anna, $anna);
$query_WADATotals = "SELECT SUM(PaymentDebit) AS Debits, SUM(PaymentCredit) AS Credits, SUM(PaymentDebit) - SUM(PaymentCredit) as Balance FROM Payments LEFT JOIN Users ON Users.UserID = Payments.PaymentClientID LEFT JOIN ContractTracking ON ContractTracking.ContractID = Payments.PaymentContractTrackingID";
setQueryBuilderSource($query_WADATotals,$WADbSearch2,false);
$WADATotals = mysql_query($query_WADATotals, $anna) or die(mysql_error());
$row_WADATotals = mysql_fetch_assoc($WADATotals);
$totalRows_WADATotals = mysql_num_rows($WADATotals);
?>



to:

<?php
$maxRows_WADAPayments = 1000;
$pageNum_WADAPayments = 0;
if (isset($_GET['pageNum_WADAPayments'])) {
$pageNum_WADAPayments = $_GET['pageNum_WADAPayments'];
}
$startRow_WADAPayments = $pageNum_WADAPayments * $maxRows_WADAPayments;

mysql_select_db($database_anna, $anna);
$query_WADAPayments = "SELECT PaymentsID, `Users`.`UserFirstName` AS Users_UserFirstName, Users.UserSurname, `ContractTracking`.`PackageID` AS ContractTracking_PackageID, PaymentDate, PaymentDocno, PaymentDebit, PaymentCredit FROM Payments LEFT JOIN Users ON Users.UserID = Payments.PaymentClientID LEFT JOIN ContractTracking ON ContractTracking.ContractID = Payments.PaymentContractTrackingID WHERE PaymentDebit > 0 OR PaymentCredit > 0 ORDER BY Users.UserSurname ASC, `Users`.`UserFirstName` ASC, PaymentDate ASC";
setQueryBuilderSource($query_WADAPayments,$WADbSearch1,false);
$query_limit_WADAPayments = sprintf("%s LIMIT %d, %d", $query_WADAPayments, $startRow_WADAPayments, $maxRows_WADAPayments);
$WADAPayments = mysql_query($query_limit_WADAPayments, $anna) or die(mysql_error());
$row_WADAPayments = mysql_fetch_assoc($WADAPayments);

if (isset($_GET['totalRows_WADAPayments'])) {
$totalRows_WADAPayments = $_GET['totalRows_WADAPayments'];
} else {
$all_WADAPayments = mysql_query($query_WADAPayments, $anna);
$totalRows_WADAPayments = mysql_num_rows($all_WADAPayments);
}
$totalPages_WADAPayments = ceil($totalRows_WADAPayments/$maxRows_WADAPayments)-1;
?>




NOTE: the recordset criteria you mention is contrary to what you originally wrote, that is the basis for the confusion.

  and that items with a 0 in PaymentDebit AND 0 in PaymentCredit should not be shown  



that is why I suggested using AND.

Sign in to reply to this post

Blikbrein

Ok, thanks. Apologies for the misunderstanding. Why does the recordset sometimes duplicate? Normally I see this and delete the duplication, but this time I missed it. I think it happens with complex queries...?

Will let you know if it worked after I deleted and retried.

Sign in to reply to this post

Blikbrein

Tried it and still get all the records instead of filtered results... I attached the changed file for you to look at again. Thanks

Attached Files
Transaction_results.php
Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.

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