When I test the following code it doesn't display the month and year above the article titles. It displays the article titles all right. Why is this happening? Can someone please help me solve this problem? Thanks in advance.
Code:
require "config2.php";
if(!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 5;
// Figure out the limit for the query based
// on the current page number
$from = (($page * $max_results) - $max_results);
$result = mysql_query ("SELECT DATE_FORMAT(selectMonth, '%M') AS month, DATE_FORMAT(selectYear, '%Y') AS year, articleid, articletitle FROM items LIMIT $from, $max_results");
if ( mysql_num_rows ( $result ) > 0 )
{
$c_month = '';
$c_year = '';
echo "<br />";
while ( $row = mysql_fetch_assoc ( $result ) )
{
if ( $row['year'] != $c_year )
{
echo "<h3>" . $row['year'] . "</h3><br />";
$c_year = $row['year'];
}
if ( $row['month'] != $c_month )
{
echo "\t<h4>" . $row['month'] . "</h4><br />";
$c_month = $row['month'];
}
echo '<a href=article.php?articleid='. $row['articleid'] .'>' . $row['articletitle'] . '</a><br />';
}
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) AS Num FROM `items`"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>";
if ($page == 1) {
echo "Previous ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
if ($page == $total_pages) {
echo " Next";
} else {
echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">Next</a>";
}
echo "</center>";
mysql_close();