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

Content-Disposition: attachment; filename=... not working as i thought it should
taken the following code from the php.net site the script is not working.

what is not happeni

Not connecting to DB using ruby, error:env.c:257:in oci8lib.so: ORA-12154:
Hi All,

I am trying to connect to the database server from the client server using ruby and f

form problem
Hi all, I think this is going to be easy to resolve but for I have been looking at it to long and I

Not showing whole name with mail () script
I sent up a simple mail form with the PHP mail() script. One problem is when it sends an email with

This must be easy , pulling the last record of the day, every day, from a txt
I have a txt file logging weather data every minutes (so 1 record per minute). I want to extract the

SAP Project Module
I have seen in the SAP Project Module,plan cost and budget are not equal and even difference is sign

check_changed_data - I can't get data from the called method event
I use check_changed_data to trigger my event method.

The method delivers er_changed_data.

Passing PHP variables from one page to another
Hello-

I'm having trouble figuring out how to transport a variable from one php file to anoth

Remove directories not empty
hi,
i have an array that contains some names (1,4,6,56...). Every integer is a name of a folder.<

values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a data

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