Link to home
Start Free TrialLog in
Avatar of richardwalton
richardwalton

asked on

How to sort data from Mysql table by month

Hello there,

I have created a PHP page that retrieves two columns from a MySQL db (date and amount). What i can't seem to comprehend is the next step... how to sum the amount and show it by month name and year as below.
The Mysql table i have consists of three columns:

-ID Autoincrement
-Date Date
-Minutes Int(11)

This is how i would like to have the data.

January 2001              45673
February 2001            34455
March 2001                23747
April 2001                  86464
May 2001                   6363
June 2001                   0
etc..

Here is my PHP code so far...
----------------------------------
<?php
// connect to the database
include("../include/irm.inc");

$query = "SELECT Date, Minutes FROM tbl_Minutes ORDER BY Date";

$sth = $adb->prepare($query);
if($sth)
{
        $res = $sth->execute();
        $numrows = $sth->rows();
        for($i = 0; $i < $numrows; $i++)
          {
                $result = $sth->fetchrow_hash();
                $Date = $result["Date"];
                $Minutes = $result["Minutes"];
                PRINT "$Date  ";
                PRINT "$Minutes <BR>";
         }
        $sth->finish();
} else
{
    PRINT "Could not prepare query: ".$sth->errstr."<br>\n";
}
?>
------------------------------------------
Any pointers, ideas or examples would be greatly appreciated. Thanks alot.
Richard.
ASKER CERTIFIED SOLUTION
Avatar of CosminB
CosminB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
skullnobrains:

Quoting the question (emphasis mine):
>>>What i can't seem to comprehend is the next step... how to SUM THE AMOUNT and show it by month name and year as below.
Avatar of skullnobrains
skullnobrains

most sorry snoyes, u were pertinent as usual and i misunderstood the question.