re:Totalling a variable in a while loop
| From: | Joseph H Blythe | Date: | Mon, 21 Feb 2000 02:08:02 +0000 |
| Subject: | re:Totalling a variable in a while loop | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10546@lists.php.net to get a copy of this message | ||
David Robley wrote:
> 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.
>
funnily enough this is exactly what I had written except in php like follows:
mysql_query("SELECT SUM(ItemTotal) AS grand_total FROM Items WHERE
UserID='$Cookie'");
this doesn't seem to work the total of all the columns under Items that belong
to UserID (which is an cookie) should be in $grand_total?
does this work on multiple rows? It seems to return nothing at all? Why?
Joseph Blythe
mailto:joe.blythe@binarylogic.com.au