[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
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
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
[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,
, 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
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 :-)
[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
7 matches
Mail list logo