Get Total From While Loop


Posted on 16th Feb 2014 07:03 pm by admin

I'm trying to get the total for each product and add them for a Grand Total to list outside the loop or only echo once I can do the addition but it will echo 5 time in the loop.
How would I go about doing this?
Thanks in advance for your help.
Code: <?php
Did you know?Explore Trending and Topic pages for more stories like this.

$cart2="SELECT * FROM products WHERE pro_indid='glass'";

$res2 = mysql_query($cart2) or die('Error, query failed 2');

while($cr2=mysql_fetch_array($res2)){

$totrow=$cr2["total"];
///the $totrow will echo below 5 time each price in database 5.67 which the total should be 28.35 //
echo $totrow;
}

///Output of total would be $28.35

?>
The output I'm looking for would be like so

5.67
5.67
5.67
5.67
5.67

GrandTotal:28.35
No comments posted yet

Your Answer:

Login to answer
74 Like 25 Dislike
Previous forums Next forums
Other forums

update the selected existing records of database
Hi frndz,
I am new to php and get stuck....

Edit.php > Update.php > Updatea

Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there

Passing an array of values From VB6.0 to Oracle PL/SQL Function
Basically we are using VB6.0.

When we try to pass an array from VB6.0 to an Oracle PL/SQL

Problems with array
This code is the last lines in an upload script that uploads 4 images at the same time and writes th

PHP Code reffering to database, doing something wrong.. pls help
Well i am quite new with PHP
and for school we have to make a PHP script which reffers to a Data

sql error
I have been looking at this code for 20mins and can't work out what I am doing wrong. There is somet

FROM_UNIXTIME($phpdate);
Hello,

I tried to use this :

$date = FROM_UNIXTIME($phpdate);

ANd I was t

PHP5/Zend 2.0 - Resources
PHP5 Snapshots
http://snaps.php.net/

ZEND 2.0 Feature Overview and Design (PDF File

login box shows up again after logging in 2nd login works
Hello,

I am having trouble on my site Lockerz.rack111.com where when you login the login box

Sessions Value Not Saved
Hi,

Im making a login form and im using this code:
Code: if($login=="true"){

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash