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 P

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 combinatio

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 @idsu

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? $val) $rowTotal += $val; // display whatever is needed from $row $rowTotals[] = $rowTotal; // or echo it out to the last column of the table } ?> [/snip] :^] Or based on the original query; while($row

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("" . $row->value . "\n"); >print("" . $row->another_value . "\n"); >$value1 = $value1 + $row->value; >$value2 = $value2 + $row->another_value; > } > > Challenge; Can this be made as simple for rows too? $val)

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

2002-09-06 Thread Richard Black
One thing I would add to Jay's out loud thoughts... Always consider alternative approaches. Using a single query and calculating the totals at the same time is fine if you have a small dataset, or (as in this case) are producing page totals (I'm assuming the dataset is paged to fit all on one pag