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.in c");
$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.
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.in
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
most sorry snoyes, u were pertinent as usual and i misunderstood the question.
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.