php mysql report month and ytd

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to create a report that shows month totals and year to date
totals together but do not know how to go about it.  This is what I
have so far to get the month totals:

$date = '20041101000000';

$date1 = '20041201000000';

$result = mysql_query("select a1.part Part, sum(a1.quantity)
Totalordered from a1 where a1.datesold > $date and a1.datesold < $date1
group by a1.part");

echo "<table>";

while ($row = mysql_fetch_row($result)) {
echo "<tr>";
for ($i=0; $i<mysql_num_fields($result); $i++) {
echo "<td>";
echo "<font face='arial,helvetica' font

echo "</td>";

echo "</tr>\n";

echo "</table>";

This displays the month totals fine but I want to add a column next to
the month and call it YTD with a different date range.  Any ideas?

Re: php mysql report month and ytd

Quoted text here. Click to load it

 From the name of that column YTD would that be "Year to date", i.e. a running
total? If it's a running total of the data displayed, then you could add up in
PHP and display that in another column. If it needs to work off data outside
the range queried, you're going to have to do another SQL query for it.

< Space: disk usage analysis tool

Re: php mysql report month and ytd

Thanks Andy, I will give that a try and create another query.

Site Timeline