Re[2]: [PHP] Average Number For Math Functions
| From: | Tom Rogers | Date: | Fri, 30 Aug 2002 05:20:38 +0000 |
| Subject: | Re[2]: [PHP] Average Number For Math Functions | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114600@lists.php.net to get a copy of this message | ||
Hi,
Friday, August 30, 2002, 3:10:09 PM, you wrote:
J> I am still very new to PHP so things are still a little foreign to me - what
J> exactly is the SUM finction - I tried to locate one on both the PHP and
J> MySQL site but found nothing!
J> Thanks ~ John
J> "Volve" <php@volved.com> wrote in message
J> news:02d901c24fd5$aba46020$7800a8c0@idiom...
>> What database are you using?
>>
>> MySQL has a SUM function which automatically selects the total of a
J> column.
>>
>> -VolVE
>>
>> ----- Original Message -----
>> From: "JohnP" <aerc@aerc.biz>
>> To: <php-general@lists.php.net>
>> Sent: Thursday, August 29, 2002 21:25
>> Subject: Re: [PHP] Average Number For Math Functions
>>
>>
>> > Ok so how do I sum up an entire column in my db?
>> > For example if one row is : 1 , the next is 2, and the next is 1 - I
J> need
>> to
>> > have a total of 4 and the be able to divide by the num_rows
>> >
>> > The problem I ma having is the "inside" row addition
>> >
>> >
>> >
>> >
>> > "Martin Towell" <martin.towell@world.net> wrote in message
>> >
>> > news:6416776FCC55D511BC4E0090274EFEF5034CFD12@exchange.world.net...
>> > > just sum them up and divide by the count - making sure to deal with a
>> > count
>> > > of zero
>> > >
>> > > -----Original Message-----
>> > > From: JohnP [mailto:aerc@aerc.biz]
>> > > Sent: Friday, August 30, 2002 10:56 AM
>> > > To: php-general@lists.php.net
>> > > Subject: [PHP] Average Number For Math Functions
>> > >
>> > >
>> > > Ok I looked at all the math functions for PHP but saw no way of
>> returning
>> > > the average of a set of numbers - I plan on using this for a rating
>> > system -
>> > > any help?
>> > >
>> > > --
>> > > John
>> >
>> >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>>
Try this replacing field and table as needed
$result = mysql_query("SELECT SUM(field) AS fsum, AVG(field) AS favg FROM table WHERE
field='whatever'");
--
regards,
Tom