Re: Calculating Totals from table columns without a second query to the DB
| From: | timo stamm | Date: | Mon, 09 Sep 2002 23:44:05 +0000 |
| Subject: | Re: Calculating Totals from table columns without a second query to the DB | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-115792@lists.php.net to get a copy of this message | ||
Hi Jay,
you suggestion does not make any difference.
The problem is that @idsum seems to be destroyed for every row!
Is there any other access method on a query that works properly or do I have to live with different results of the very same query asked directly in MySQL and asked through PHP?
Timo
Am Montag den, 9. September 2002, um 15:04, schrieb Jay Blanchard:
[snip] I would like to be able to sum up a collumns values already in MySQL. The following query will sum up all values of the column 'id': SELECT @idsum:=(IFNULL(@idsum, id)+id), id FROM yourtable; Now a question to the PHP/MySQL experienced: Why does this type of query not work in combination with PHP? I am using query above as $query and do the following standard procedure: [/snip] Good point! Now as to your question, try this... SELECT @idsum:=(IFNULL(@idsum, id)+id) AS idsum, id FROM yourtable; When you output your query info output the value as $row->idsum; HTH! Jay