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
https://forums.phpfreaks.com/topic/171161-solved-displaying-articles-by-date/
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>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.