Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-29-2005, 04:08 PM PHP Mathematics
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hi,

I have a form that basically retrieves data from a MySQL database. One of the fields within the database has a dollar amount. I have used the following code to retrieve the data but like a running total of the amount of records I would like a running total of the field "Arrears Paid" for the records selected. Can anyone point me in the right direction on how to code this? The only thing I could find on the subject doesn't use a database to get its numbers from.

Thanks -

PHP Code:
while ($query_res mysql_fetch_array($query_run)) {
        print 
"<b>Date Entered: " $query_res['Entered_Month'] . " " $query_res['Entered_Day'] . ", " $query_res['Entered_Year'] . "</b><br>";
        print 
"Agent: " $query_res['Agent'] . "<br>";
        print 
"Customer: " $query_res['Customer_Name'] . "<br>";
        print 
"Account: " $query_res['Account_Number'] . "<br>";
        print 
"Product: " $query_res['Product_Type'] . "<br>";
        print 
"Balance: " $query_res['Balance_Owing'] . "<br>";
        print 
"Arrears Paid: " $query_res['Arrears_Paid'] . "<br>";
        print 
"Settled: " $query_res['Amount_Settled'] . "<br>";
        print 
"Settled On: " $query_res['Date_Settled'] . "<br>";
        print 
"<hr>";
        } 
merlin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-29-2005, 05:17 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
PHP Code:
<?php

$totalArrears 
0.00;

while (
$query_res mysql_fetch_array($query_run)) 

        print 
"<b>Date Entered: " $query_res['Entered_Month'] . " " $query_res['Entered_Day'] . ", " $query_res['Entered_Year'] . "</b><br>"
        print 
"Agent: " $query_res['Agent'] . "<br>"
        print 
"Customer: " $query_res['Customer_Name'] . "<br>"
        print 
"Account: " $query_res['Account_Number'] . "<br>"
        print 
"Product: " $query_res['Product_Type'] . "<br>"
        print 
"Balance: " $query_res['Balance_Owing'] . "<br>"
        print 
"Arrears Paid: " $query_res['Arrears_Paid'] . "<br>"
        print 
"Settled: " $query_res['Amount_Settled'] . "<br>"
        print 
"Settled On: " $query_res['Date_Settled'] . "<br>"
        print 
"<hr>"

        
$totalArrears += (double) $query_res['Arrears_Paid']

        }

// now $totalArrears will contain the grand total of all arrears.

?>
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 03-29-2005, 05:29 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hi Kyrnt,

Thanks so much for your reply. I have been killing myself on what I'm sure is a very easy problem. I added your code but I'm getting a Parse Error on the last line. I have tried it with and without the ";". Could you possibly see another alternative?

The line I'm getting the parse error on is: $totalArrears += (long) $query_res['Arrears_Paid'];

Thanks Again
merlin is offline
Reply With Quote
View Public Profile
 
Old 03-29-2005, 06:36 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
merlin, try it by casting to (double) instead of (long). I did accidentally leave off the semicolon -- it is required -- thanks for catching that mistake.

And just to be safe, let's add some additional parentheses:

PHP Code:
$totalArrears += ((double) $query_res['Arrears_Paid'] ); 
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Reply     « Reply to PHP Mathematics
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35655 seconds with 12 queries