I have tried everything and still can't figure it out. It's for an archive page. The problem is that only the first month (January) of the 2008 gets displayed. I want to display it like this:
Year
Month
Year
Month
// Select posts grouped by month and year
$sql = "SELECT DATE_FORMAT(postdate, '%M %Y') AS monthyear, MONTH(postdate) AS month, YEAR(postdate) AS year, DATE_FORMAT(postdate, '%M') as displaymonth, count(*) AS count FROM posts GROUP BY monthyear ORDER BY year DESC, month ASC";
$result = mysql_query($sql);
$myposts = mysql_fetch_array($result);
//
$month = $myposts["month"];
$year = $myposts["year"];
$sql2 = "SELECT title, DATE_FORMAT(postdate, '%M %Y'), MONTH(postdate) AS month, YEAR(postdate) AS year, DATE_FORMAT(postdate, '%d') AS day FROM posts WHERE MONTH(postdate) = $month AND YEAR(postdate) = $year ORDER BY day DESC";
$result2 = mysql_query($sql2);
$myposts2 = mysql_fetch_array($result2);
<?php
$previousyear = "";
if($myposts) {
do {
$year = $myposts["year"];
$month = $myposts["month"];
$monthyear = $myposts["monthyear"];
$displaymonth = $myposts["displaymonth"];
$count = $myposts["count"];
if ($year != $previousyear) {
if ($previousyear != "") {
echo "</ul>\n";
}
echo "<h3>$year</h3>\n";
echo "<ul>\n";
$previousyear = $year;
}
$plural = ($count==1) ? "" : "s";
echo "<li>\n<a href='archive.php?year=$year&month=$month'>$displaymonth</a> ($count post$plural)";
//
echo "\n<ul>\n";
do {
$title = $myposts2["title"];
echo "<li>$title</li>";
} while ($myposts2 = mysql_fetch_array($result2));
echo "\n</ul\n";
//
echo "\n</li>\n";
} while ($myposts = mysql_fetch_array($result));
echo "\n</ul>\n";
}
break;
}
?>
This to show that all tags are balanced.
<ul>Start
<li>1
<a href="http://localhost/dmelo/dmeloperspective.com/blog/archive.php?year=2008&month=1">January</a> (3 posts)
<ul>1
<li>This is to test Author</li><li>Test Blog</li><li>This is the title</li>
</ul>1
</li>1
<li>2
<a href="http://localhost/dmelo/dmeloperspective.com/blog/archive.php?year=2008&month=2">February</a> (1 post)
<ul>2
<li></li>
</ul>2
</li>2
</ul>End
<h3>2007</h3>
<ul>Start
<li>3
<a href="http://localhost/dmelo/dmeloperspective.com/blog/archive.php?year=2007&month=2">February</a> (2 posts)
<ul>3
<li></li>
</ul>3
</li>3
</ul>End
Thanks.