Jump to content

[SOLVED] Displaying articles by date


timmah1

Recommended Posts

I'm trying to show news like this, separating by date

 

8-20-2009

TITLE

 

8-19-2009

TITLE

TITLE

TITLE

TITLE

 

8-18-2009

TITLE

TITLE

 

 

So far, this only shows the top date.

 

<?php				
				$query = "SELECT date_posted FROM nfl_feeds_history ";
				$w = mysql_query($query) or die(mysql_error());

					while($b = mysql_fetch_array($w)){
						$posted = $b['date_posted'];


					$archived = mysql_query("SELECT * FROM nfl_feeds_history WHERE date_posted = '$posted'");
				}
					echo date("F j, Y", strtotime($posted));
					while($t = mysql_fetch_array($archived)){

							$title = $t['title'];
							$id = $t['id'];					

					echo "<h2><a href='history_news.php?id=$id'>$title</a></h2>";					
			}
?>

Can anybody help me out here?

 

Thanks in advance

Link to comment
Share on other sites

$query = 'SELECT * FROM nfl_feeds_history ORDER BY date_posted';
$result = mysql_query($query);
if ($result && mysql_num_rows($result)) {
    echo '<dl>';
    $currentDate = null;
    while ($row = mysql_fetch_assoc($result)) {
        if (strcmp($currentDate, $row['date_posted'])) {
            $currentDate = $row['date_posted'];
            echo '<dt>', date('F j, Y', strtotime($row['date_posted'])), '</dt>';
        }
        echo '<dd>', $row['title'], '</dd>';
    }
    echo '</dl>';
}

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.