Re: pulling numbers from a column and getting a total

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Natalie and Miles! The loop thing worked. What I had tried before was
put the echo inside the loop and it wasn't working, but now it does, w00t!
Thanks!

On 7/26/06, Miles Thompson <miles@xxxxxxxxxxxxxxxxx> wrote:

At 10:27 AM 7/26/2006, Dave W wrote:

>Hi, I was just wondering on how I could get a whole column full of
integers
>and added them up and display that total? I currently use a for loop to
>display the whole column in a table, but I wanted to add all those
numbers
>up.
>
>Thanks.
>
>--
>Dave W

Dave,

You're v. close to an answer. Think about it a bit.

Initialize a variable before your loop, setting it to zero.
         $tot = 0;
In the loop, add the amount to that variable,
         $tot += $num_to_add;
OR
         $tot = $tot + $num_to_add;

After the loop, echo $tot.

HTH - Miles


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.394 / Virus Database: 268.10.4/399 - Release Date: 7/25/2006

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Dave W

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux