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

Not adding to db
Hi, I can't figure out why it won't add the record to the database. It's just a simple form to get

simplexml and xpath - Need some help
Hello,

I am trying to parse an xml which comes back from Amazon and I am trying to know how m

unserialize help, getting errors
hi all ,
I got a form with 6 fields (2 input and 4 select box), when the page loads one block is

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

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

reorder sql query
ok so i have this very simple code:
Code: $query = "SELECT search_keywords, COUNT(search_key

MYSQL INSERT ID NOT WORKING
Code: $id = mysql_insert_id();
header("Location: ./?view=$id");
Why $id pulling blan

Call db table from any PHP file
Hi,

I want to be able to call a database table that will be setup in another file called init

Comment Mod System Effects all rows...
Sorry if its confusing but here is whats going on: I have a table in a database called comments and

Curl & sessions PLS HELP
Hello,

I have a problem with curl and sessions and i will try to explain the best i could.

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