Page 1 of 1

Looping data and sum it up error

Posted: Tue Feb 17, 2009 11:16 pm
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.

Re: Looping data and sum it up error

Posted: Tue Feb 17, 2009 11:36 pm
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.