Jump to content


Photo

Month and year isn't displaying above the articles???


  • Please log in to reply
No replies to this topic

#1 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 21 October 2006 - 04:30 AM

I am trying to display article titles underneath the month and year they were added to the database table but the month and year isn't displaying. Can someone please help me solve this problem? Thanks in advance.

Here is the code that I am working with:
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, articletitle, articleid 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 "\t\t" . $row['articletitle'] . "<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();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users