Tuesday, June 9

Addendum about Sum()

It seems like it's totally okay if you're selecting just the sum to leave out the group by part. I needed to pull data and put it in rows, then show the total on the bottom. I don't know if I necessarily did this the _right_ way, but it worked.

My two queries:

$query1 = "SELECT * FROM table";
$query2 = "SELECT sum(amt) FROM table";
It was in a table so I used a while loop to add rows, then after the loop, added
<tr>
<td>TOTAL</td>
<td>$<?=number_format($row1['sum(pay_amt)'],2)?></td>
</tr>

of course, don't forget to define them. i defined row1 before the while loop.

No comments: