Hi,
$query="SELECT my_id, mydate, MONTH(mydate) AS month FROM mytable ORDER BY month";
$result = mysql_query($query) or die("Query failed");
$previous_month = "";
while ($myrow = mysql_fetch_array($result))
{
$id = $myrow["my_id"];
$month = $myrow ["month"];
$mydate = $myrow["mydate"];
if ($month != $previous_month)
{
print "<HR>";
print "Month : $month<BR>";
$previous_month = $month;
}
print "my_id = $my_id<BR>";
print "my_date = $my_date<BR>";
// print the rest of the data here
}
This will work for a given year, but you also need to do
a sort on the year (alone) in the SQL statement, otherwise
the January of year 2002 will follow the January of year 2001
which may not be what you really want 😃
Left as an exercise for you ! (the idea is the same as for the
month)
Hervé.