re:Totalling a variable in a while loop
| From: | Joseph H Blythe | Date: | Tue, 22 Feb 2000 00:13:22 +0000 |
| Subject: | re:Totalling a variable in a while loop | ||
| References: | 1 2 3 4 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10615@lists.php.net to get a copy of this message | ||
Lukasz Felsztukier wrote:
>
> > 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 ""
>
> Query is one thing - php variables is quite another ;-)
> Just do the following:
> $result = mysql_query("SELECT SUM(ItemTotal) FROM Items WHERE
> UserID='cc2b438a843e93612ea3a4d5936ee547'");
> list($grand_total) = mysql_fetch_row($result);
> Now you'll have your thingy in the variable
>
$result = mysql_query("SELECT SUM(ItemTotal) FROM Items AS grand_total WHERE
UserID='$Cookie'");
list($grand_total) = mysql_fetch_row($result);
Hey thanks a million to all who helped me through this one, I seem to get confused still with the
query just
really being a pointer to the result index or whatever , this works exactly as intended now it will
add up
all my items under ItemTotal where any rows with UserID==$Cookie and return the grand_total as an
php
variable.
You made my day :-)
Joseph Blythe
mailto:joe.blythe@binarylogic.com.au