RE: [PHP] Calculating Totals from table columns without a second query to the DB

From: Date: Mon, 09 Sep 2002 13:04:20 +0000
Subject: RE: [PHP] 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-115731@lists.php.net to get a copy of this message
[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

« previous php.general (#115731) next »