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

function not returning the correct value
I have a program that needs to return a value from a function. I have an output statement inside the

PHP Multiples of 2, Show posts...not working (wordpress)
I have been using this code to show div.example with 6 li columns inside it, each li is a post with

mysql select query problem
how can i select multiple fields from multiple table in one query like

i have table name t1 a

pop3 and fsockopen
So I am able to connect to the pop3 server, log in, and check how many messages there are. I am hav

how to remove in php string display
My code is

$message="We're looking at developing our website.";

$body= "

Install page
How do I make it so when a user submits information on the Install page, it'll right it into the cor

Array to string conversion
Can anyone help me with this?

Notice: Array to string conversion in /home/..../index.php on l

what does this mean? +=
is anyone able to explain what this code is saying?

i had it written for me awhile back and n

Mass activity scheduling
Hi experts,

Im facing some problems to deal with mass activity jobs.
When I run some

Need understanding of this bit of code
Code: <?php
// WHERE clause filters
$arrSQLFilters = array();

//

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