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

2002-09-09 Thread 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

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

2002-09-09 Thread timo stamm
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

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

2002-09-07 Thread timo stamm
Hi Jay, MySQL deserves some more respect. It's language is quite potent. Have you had a look on COUNT()? It is suited well for... well, counting. 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

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

2002-09-06 Thread Jay Blanchard
[thinking out loud] For small result sets where I am looking for column totals I generally issue 2 queries to the database, one for the data and one for the totals. This works fine, but for some things the database returns 100's or 1000's of records. To make this easier to use I page the records,

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

2002-09-06 Thread Richard Black
, DataVisibility Ltd - http://www.datavisibility.com Tel: 0141 951 3481 Email: [EMAIL PROTECTED] -Original Message- From: Jay Blanchard [mailto:[EMAIL PROTECTED]] Sent: 06 September 2002 16:33 To: [EMAIL PROTECTED] Subject: [PHP] Calculating Totals from table columns without a second query

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

2002-09-06 Thread Jon Haworth
Hi Jay, while($row = mysql_fetch_object($result)){ print(td . $row-value . /td\n); print(td . $row-another_value . /td\n); $value1 = $value1 + $row-value; $value2 = $value2 + $row-another_value; } Challenge; Can this be made as simple for rows too? thinking out loud :-)

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

2002-09-06 Thread Jay Blanchard
[snip] Challenge; Can this be made as simple for rows too? thinking out loud :-) ?php $rowTotals = array (); while ($row = mysql_fetch_object($result)) { $rowTotal = 0; foreach ($row as $key=$val) $rowTotal += $val; // display whatever is needed from $row