By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,336 Members | 2,315 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,336 IT Pros & Developers. It's quick & easy.

php mysql report month and ytd

P: n/a
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
size='1'>$row[$i]</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?

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 21 Dec 2004 06:01:55 -0800, "chubbywillie55" <wi******@yahoo.com> wrote:
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
size='1'>$row[$i]</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?


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.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
Thanks Andy, I will give that a try and create another query.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.