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

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Raisario
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Nov 26, 2002 2:24 pm

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

Postby Raisario » Mon Dec 09, 2002 4:31 pm

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

wiredme
New php-forum User
New php-forum User
Posts: 7
Joined: Sun Dec 08, 2002 9:02 pm

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

Postby wiredme » Mon Dec 09, 2002 11:31 pm

look at the code below i add some variables, just print the total price try it.


Raisario wrote: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


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron