Jump to content

Order mysql output by date


phingoc

Recommended Posts

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';
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/248902-order-mysql-output-by-date/
Share on other sites

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.