Jump to content

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


cturner

Recommended Posts

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:
[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, 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();
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.