Adding numbers pulled out from the database..need sample.

A

Anonymous

Guest
Here is the code I used to display the query results in a table on a page:
------------------------------------------------------------------------------------
//displaying data in a table
while ( $a_row = mysql_fetch_array($query_coupon))
{
print "<TR align=center>\n";
print "<TD width=100>{$a_row['coupon_id']}</TD>\n";
print "<TD width=100>{$a_row['percent_discount']}</TD>\n";
print "<TD width=100>{$a_row['description']}</TD>\n";
print "<TD width=100>{$a_row['status']}</TD>\n";
print "<TD width=100>{$a_row['purchase_amount']}</TD>\n";
print "<TD width=100>{$a_row['retailer_ordernum']}</TD>\n";
print "<TD width=100>{$a_row['purchase_time']}</TD>\n";
print "<TD width=100>{$a_row['username']}</TD>\n";
print "<TR>\n";
}
-----------------------------------------------------------------------------------

Now I need to get and display the total of all the "purchase_amount" data thats has been pulled out and displayed in the table. Can somebody pls help me how to get the total and display it? Sample code would be the best. :D
 
look at the code below i add some variables, just print the total price try it.


Raisario said:
Here is the code I used to display the query results in a table on a page:
------------------------------------------------------------------------------------
//displaying data in a table
$total=0;
while ( $a_row = mysql_fetch_array($query_coupon))
{
print "<TR align=center>\n";
print "<TD width=100>{$a_row['coupon_id']}</TD>\n";
print "<TD width=100>{$a_row['percent_discount']}</TD>\n";
print "<TD width=100>{$a_row['description']}</TD>\n";
print "<TD width=100>{$a_row['status']}</TD>\n";
print "<TD width=100>{$a_row['purchase_amount']}</TD>\n";
print "<TD width=100>{$a_row['retailer_ordernum']}</TD>\n";
print "<TD width=100>{$a_row['purchase_time']}</TD>\n";
print "<TD width=100>{$a_row['username']}</TD>\n";
print "<TR>\n";

$itemprice=$a_row['purchase_amount'];
$total=$total + $itemprice;
}

print "$total";
-----------------------------------------------------------------------------------

Now I need to get and display the total of all the "purchase_amount" data thats has been pulled out and displayed in the table. Can somebody pls help me how to get the total and display it? Sample code would be the best. :D
 
Back
Top