timmah1 Posted August 20, 2009 Share Posted August 20, 2009 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 More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 $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 https://forums.phpfreaks.com/topic/171161-solved-displaying-articles-by-date/#findComment-902595 Share on other sites More sharing options...
timmah1 Posted August 20, 2009 Author Share Posted August 20, 2009 thank you Link to comment https://forums.phpfreaks.com/topic/171161-solved-displaying-articles-by-date/#findComment-902598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.