pulling numbers from a column and getting a total

pulling numbers from a column and getting a total

am 26.07.2006 15:27:03 von Dave W

------=_Part_248268_22809236.1153920423891
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

------=_Part_248268_22809236.1153920423891--

Re: pulling numbers from a column and getting a total

am 26.07.2006 16:04:16 von Natalie Leotta

------=_Part_105275_22515.1153922656884
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

http://www.techonthenet.com/sql/sum.php

That should help, Dave!

Natalie

On 7/26/06, 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
>
>


--
Natalie Leotta
Independent Consultant
Arbonne International
607-785-2151
http://www.arbonne.com/

------=_Part_105275_22515.1153922656884--

Re: pulling numbers from a column and getting a total

am 26.07.2006 16:06:25 von Natalie Leotta

------=_Part_105384_6449133.1153922785942
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I just reread your question and realized that you said you're already
displaying each number, so instead you might be better off with a variable
that you initialize to 0 and then in each iteration of your for loop add on
that value.

Natalie

On 7/26/06, Natalie Leotta wrote:
>
> http://www.techonthenet.com/sql/sum.php
>
> That should help, Dave!
>
> Natalie
>
>
> On 7/26/06, 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
> >
> >
>
>
> --
> Natalie Leotta
> Independent Consultant
> Arbonne International
> 607-785-2151
> http://www.arbonne.com/
>



--
Natalie Leotta
Independent Consultant
Arbonne International
607-785-2151
http://www.arbonne.com/

------=_Part_105384_6449133.1153922785942--

Re: pulling numbers from a column and getting a total

am 26.07.2006 16:07:12 von Miles Thompson

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

Re: pulling numbers from a column and getting a total

am 26.07.2006 17:12:29 von Dave W

------=_Part_252503_5357622.1153926749570
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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 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

------=_Part_252503_5357622.1153926749570--

Re: pulling numbers from a column and getting a total

am 27.07.2006 12:30:28 von robleyd

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.
>

You could use the SUM function in your DB to do the work for you.


Cheers
--
David Robley

Power corrupts; absolute power is even more fun.
Today is Pungenday, the 62nd day of Confusion in the YOLD 3172.

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