Re: [PHP4BETA] re:Totalling a variable in a while loop
| From: | Joseph H Blythe | Date: | Mon, 21 Feb 2000 23:43:19 +0000 |
| Subject: | Re: [PHP4BETA] re:Totalling a variable in a while loop | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10613@lists.php.net to get a copy of this message | ||
Joseph H Blythe wrote:
> 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?
>
This works as a straight MYSQL command
SELECT SUM(ItemTotal) AS grandTotal FROM Items WHERE
UserID='cc2b438a843e93612ea3a4d5936ee547';
But I think the problem might lie in the alias or something how do I access it
through php $grand_total? It returns ""
The value $Cookie does hold the right string, so I don't see what else could be
causing this?
Thanks :-)
Joseph Blythe
mailto:joe.blythe@binarylogic.com.au