Re: [PHP4BETA] re:Totalling a variable in a while loop

From: Date: Mon, 21 Feb 2000 01:30:28 +0000
Subject: Re: [PHP4BETA] re:Totalling a variable in a while loop
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-10544@lists.php.net to get a copy of this message
On 21 Feb, Joseph H Blythe wrote: > Hey thanks, > > I have tried this out but the manual (MYSQL) a little sparse on this > clause, what ive got upto is I have inserted all the values I want totaled > into a column and now all I want to do is total all values in that column > where whatever equals whatever, so if the field I wanted to total was > called ItemTotal and I want every value added up where UserId equals > whatever how would the syntax go? SELECT SUM(ItemTotal) AS grand_total FROM table WHERE UserId = 123 should do the trick. > How do I set an alias to the SUM? That's the 'AS grand_total' part above ;-) When you reference it from PHP use the name grand_total or whatever you choose to call it. You need to do that, aliasing, for any of the mysql functions like count, min, max etc. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.version4 (#10544) next »