RE: [PHP-DB] Count database-values
| From: | Ford, Mike [LSS] | Date: | Tue, 10 Jun 2003 15:54:34 +0000 |
| Subject: | RE: [PHP-DB] Count database-values | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-28493@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Becoming Digital [mailto:subs@becomingdigital.com]
> Sent: 10 June 2003 12:15
>
> I screwed up my own code. Silly me. It should read:
Surely your first attempt is the right one? There's only ever going to be 1 Total, so why
waste a while loop trying to read more than one result row?
> $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> posneg = 'af'";
> $result = mysql_query( $query );
> while ( $total = mysql_fetch_array( $result ) )
> {
> $total = $total['Total'];
> }
>
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
>
>
> ----- Original Message -----
> From: "Becoming Digital" <subs@becomingdigital.com>
> To: <php-db@lists.php.net>
> Sent: Tuesday, 10 June, 2003 06:43
> Subject: Re: [PHP-DB] Count database-values
>
>
> > So far no problems, but I want to count all these values.
> > I tried with SUM but with the following code it doesn't work:
> >
> > $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> posneg = 'af'";
> >
> > any suggestions how to do? I want to store it in a
> variabele ($total)
> > so I can echo it. (E.g.: $total = 93.63 in this case)
>
> If you want the total, you need to do something like the following:
>
> $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> posneg = 'af'";
> $result = mysql_query( $query );
> $total = mysql_fetch_array( $result );
> $total = $total['Total'];
>
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211