Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2009, 07:49 AM
Authorized User
 
Join Date: Dec 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default Adding the sum of fines up

Hi all

I am on a final task for a tutorial I am doing about a Library which you may have already seem some posts for.

In this table I am creating I am listing customers with their:

Current total Overdue charge
and
Total Previous Charges

At the moment I have manage to get the table to display all the names once(that being only those with current overdue charges or previous charges) and then list all the charges underneath those names.

This is where my problem now lie. I struggling to work out how to total up those charges. So ideally I should have each person with only one row. The Current total overdue charge column should have a total figure in it or show as NILL and the Total Previous Charge should have a total figure in it or show NILL. But as I said currently I have each individual with all their figures listed. So each customer has several rows listed below them.

Hope this makes sense.

I am still fairly new to ASP and any help would be great. Many thanks in advance. Please see code below:



PHP Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
'Displays Customers and theirs books with fine paid/owed and those that still have an overdue book to be displayed in red%>
<%'
Has a search function%>
<%
Dim connconnStringsqlSearchCustomerFinersSearchCustomerFinesearchCustomersdueDatediffDatefineOwedfineOwedTotalcheckedInDatedueCheckDiffDate,customerName
connString 
=  "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" Server.MapPath("rltestingDB.mdb")

searchCustomers Request.Form("searchCustomers")

if 
searchCustomers <> "" then
    sqlSearchCustomerFine 
"SELECT * FROM viewAllCustomersBooks WHERE DUE_DATE < DATE() AND NAME LIKE '%" searchCustomers "%'"
else
    
sqlSearchCustomerFine "SELECT * FROM viewAllCustomersBooks WHERE DUE_DATE < DATE()" 
end if



Set conn Server.CreateObject("ADODB.Connection")
Set rsSearchCustomerFine Server.CreateObject("ADODB.Recordset")
conn.Open(connString)
rsSearchCustomerFine.Open sqlSearchCustomerFineconn
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html>
<
head>
<
title>Customer fine records</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
link href="global.css" rel="stylesheet" type="text/css">
<
style type="text/css">
<!--
.
style1 {color#FF0000}
-->
</
style>
</
head>


<
form method="post" action="personAccount.asp">
Search: <input type="text" name="searchCustomers" value="<%=searchCustomers%>" />
<
input type="submit" value="Submit" />
</
form>

<
table width="800" border="0">
<
tr>
<
th>Name</th>
<
th>Current total overdue charge</th>
<
th>Total previous charges</th>
</
tr>
<%
customerName ""%>
<%while(
rsSearchCustomerFine.eof false)%>
<%
dueDate rsSearchCustomerFine("DUE_DATE")%>
<%
checkedInDate rsSearchCustomerFine("CHECKED_IN_DATE")%>
<
tr>
        <%If 
rsSearchCustomerFine("NAME") <> customerName then%>
            <
td><%=rsSearchCustomerFine("NAME")%></td>
            <%If 
dueDate checkedInDate Then
                diffDate 
DateDiff("d",dueDate,checkedInDate)
                
fineOwed diffdate*00.20%>
                <
td>Nill</td>
                <
td id="overDueAlertPaid"><%response.Write(FormatCurrency(fineOwed))%><%=(" Paid")%></td>
            <%ElseIf (
dueDate<Date()) or (checkedInDate ""Then
                diffDate 
DateDiff("d",dueDate,Date())
                
fineOwed diffdate*00.20%>
                <
td id="overDueAlert"><%= FormatCurrency(fineOwed) %></td>
                <
td>Nill</td
            <%
End if%>
        <%Else%>
            <
td>&nbsp;</td>
            <%If 
dueDate checkedInDate Then
                diffDate 
DateDiff("d",dueDate,checkedInDate)
                
fineOwed diffdate*00.20%>
                <
td>Nill</td>
                <
td id="overDueAlertPaid"><%response.Write(FormatCurrency(fineOwed))%><%=(" Paid")%></td>
            <%ElseIf (
dueDate<Date()) or (checkedInDate ""Then
                diffDate 
DateDiff("d",dueDate,Date())
                
fineOwed diffdate*00.20%>
                <
td id="overDueAlert"><%= FormatCurrency(fineOwed) %></td>
                <
td>Nill</td
            <%
End if%>
        <%
End if%>
    <%
customerName rsSearchCustomerFine("NAME")%>
</
tr>
<%
rsSearchCustomerFine.movenext
wend
%>
</
table>




</
body>
</
html>
<%
rsSearchCustomerFine.close
Set rsSearchCustomerFine 
Nothing
conn
.close
Set conn 
Nothing
%> 
 
Old December 21st, 2009, 07:57 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

The problem is in your IF statement in your loop. You don't need any HTML in that first part of the IF. That's the place where if the name is the same you just keep adding up the values of the variables that are set to the database values.

Once the name changes you can go to the ELSE and print the one row with the values that you have added up in the first part of the IF.

But what are you going to do if someone paid one fine but is late on the other?

In that case you would need to have an IF inside the ELSE to see if they have both overDueAlertPaid and overDueAlert values unless I'm not understanding your spec.

There are many ways to handle this. It just depends on what your data is and what you want it to look like when it is printed to the page in HTML.
 
Old December 22nd, 2009, 04:14 PM
Authorized User
 
Join Date: Dec 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Smile

Thanks for the advice, yeah there are a number of others things I need to look into. Thanks for your help with this, I will try this out.

Happy Holidays!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
Sum Jonas Access VBA 1 August 4th, 2006 12:41 PM
sum utarian Access 2 March 28th, 2005 09:42 PM
need sum help! jbik BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 December 20th, 2004 05:27 PM
SUM or What bertlf Pro VB Databases 2 November 29th, 2003 02:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.