php mysql report month and ytd

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chubbywillie55

    php mysql report month and ytd

    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("se lect 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_fi elds($result); $i++) {
    echo "<td>";
    echo "<font face='arial,hel vetica' 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?

  • Andy Hassall

    #2
    Re: php mysql report month and ytd

    On 21 Dec 2004 06:01:55 -0800, "chubbywillie55 " <willie55@yahoo .com> wrote:
    [color=blue]
    >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("se lect 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_fi elds($result); $i++) {
    >echo "<td>";
    >echo "<font face='arial,hel vetica' font
    >size='1'>$ro w[$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?[/color]

    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 / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • chubbywillie55

      #3
      Re: php mysql report month and ytd

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

      Comment

      Working...