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

Do not allow posting of whitespace
Currently the script below works if the user does not type a name/message, but if i create a whitesp

Line break?
Hi, I'm new to the forum and new to php. I'm not sure if I'm using the correct terminology so here i

Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix

Character increment
Hi,

I am facing a scenario like above,but in my case i want to show up like Col A,Col B etc..

Can't find a decent web analytics!!!
I've downloaded and installed Piwik. It's location detection based on IP addresses is fairly inaccur

Inserting a variable in a link
I have this code that I want to insert for my own variable but I have no idea how. This is what I wa

At max how many columns is advisable to create in a table/view
Hi All,
I have two transaction table from which i want to create a simple view or material

Displaying image from database
Hi,

I've got a site where that's got a database behind it. Currently it has loads of items in

Recode Abap Dynpro into Web Dynpro
Hi All,
A client has asked us to look at rearchitecting a custom transaction that was developed

Uploading/Downloading files stored in MySQL database
Hey all,

This problem just came up in my website and I'm having a hard time figuring out what

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