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

how can i display php source code snippets ?
I am outputting some pho code .. and I want to display the source code so people can copy and paste

Login script (probably a simple error)
dbConfig.php
Code: <?
// Replace the variable values below
// with your specific dat

How to get all server headers like Live http Headers does
Hey all, like many of you I use the Firefox addon "Live http Headers". I'm trying to write

Creating an invoice
Using fpdf I am trying to create an invoice to send to clients. The products are sold in pricing tie

Bar charts using Graphical Framework.
I am using Graphical Frameworks(GFW) to create a chart Graphic . There is no problem with the data d

cURL and Sessions
Ohai.

So, I'm trying to cURL a bunch of things off of a page, and put them into a session. I'

How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou

How to disable direct access to a file
Suppose I've 2 Files. 1.php & 2.php

I don't want anybody to access 2.php directly fr

Customizing message/behavior
Hi,I'm using the ASP.NET membership/authorization controls in my application. Some parts of my appli

login from external site
Hi my new experience begins, Now what i am trying to do is i make three pages, login.php logout.php

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