phingoc Posted October 11, 2011 Share Posted October 11, 2011 Hi. How can i order the news that gets viewed by date? newest first. <?php include ('mysql_connect.php'); $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $url = 'comments.php?id='.$row['id']; echo '<p><b>'.$row['title'].'</b><br /> '.$row['sd'].'<br /> Skrevet av : <b>'.$row['author'].'</b><br /><br /> '.$row['post'].'<br /><br /> <a href="javascript:openComments(\''.$url.'\')">Legg til eller les komentarer.</a></p><br /><hr>'; } } else { echo 'Det er for tiden ingen nyheter'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248902-order-mysql-output-by-date/ Share on other sites More sharing options...
Maq Posted October 11, 2011 Share Posted October 11, 2011 http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html Quote Link to comment https://forums.phpfreaks.com/topic/248902-order-mysql-output-by-date/#findComment-1278283 Share on other sites More sharing options...
phingoc Posted October 11, 2011 Author Share Posted October 11, 2011 thanks.. changed this line "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY DATE DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/248902-order-mysql-output-by-date/#findComment-1278288 Share on other sites More sharing options...
Maq Posted October 11, 2011 Share Posted October 11, 2011 thanks.. changed this line "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY DATE DESC"; Sure no problem, so is everything working for you now? If so, you can mark this topic solved. Quote Link to comment https://forums.phpfreaks.com/topic/248902-order-mysql-output-by-date/#findComment-1278308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.