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

$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

Displaying a clickable playername
I am going wrong somewhere with the mysql_query, can someone please put me straight?

$playern

Custom CMS
This is a big custom CMS script I'd like to develop and would like some help atleast figuring out wh

"From field" in PHP email form
I used a wizard to create a PHP email form. I was able to customize it with the exception of the Fr

DateObject and Nulls
Hi all,

I have an array mapped to a value object. One of the items in the array is a PHP Date

ereg_replace()
Basically what i need to do is

$title = "This Suck's"

$striped = ereg_repl

Loops and Classes
I am making a template system and everything seems to be going well up until I have to loop in a var

Need help in log in and log out?
hi there all of u. i have recently created a site for someone. i have placed log in and log out and

C - Reading a file into a byte array
Hi,

I'm trying to read a file into a byte array in C. I have to use C as this is for a loadru

HTAccess auto log in?
Hi all.

Too busy driving celebs about lately so I hope someone here can help me out.

I

Creating XML with php
I need to creat an XML with php and have successfully produced a valid output.
The problem I hav

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