Looping data and sum it up error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
blocker
Forum Newbie
Posts: 5
Joined: Tue Feb 17, 2009 10:03 pm

Looping data and sum it up error

Post by blocker »

Ive just so tired just to finished my thesis. Ive got problem in php summing up while looping and filtering. here is my code:

Code: Select all

 
 
mysql_select_db($database_enamysqldb, $enamysqldb);
$query_recpayment = "SELECT amountpaid, username, SUM(amountpaid) FROM paymentsummary WHERE username = %s and foryear = %s and forlevel =%s", GetSQLValueString($colname_reclog, "text"), GetSQLValueString($_SESSION['MM_dyearnow']), GetSQLValueString($_SESSION['MM_enrolto']));
 
$recpayment = mysql_query($query_recpayment, $enamysqldb) or die(mysql_error());
 
$row_recpayment = mysql_fetch_assoc($recpayment);
$totalRows_recpayment = mysql_num_rows($recpayment);
 
$totalpayment=0;
while($row = mysql_fetch_array($recpayment)){
    $totalpayment = $totalpayment + &row['SUM(amountpaid)'];
}
$_SESSION['MM_totalbills']=$totalpayment;
?>
 
I want to sum up all the value of the amountpaid field base on a filter of the where clause in mysql query. the sum then will be stored in a variable called $totalpayment, and after the sum is stored on that variable, i want to store it in a session variable as what the code looks above. But i think there something missing in my code. It fails to run, it results error unexpected.

Pls help.

Thank you. Peace on this mother earth.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Looping data and sum it up error

Post by John Cartwright »

Duplicate threads, soliciting private help.. not a good start.

Please familiarize yourself with our forum rules before continuing to post.

Topic Locked.
Locked