Jump to content


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


Sort By Date

Recommended Posts

I'm trying to create a simpl blog for a website. And I can get it to output the entires but now I wanted the entries to be sorted by date they were submited.

Heres basicly all my code:

$host = "localhost";
$user = "***";
$pass = "****";
$database = "*****";

$conn = mysql_connect($host,$user,$pass) or die ("Unable to connect to Database");
$result = mysql_query("SELECT * FROM blog") or die(mysql_error());
while($row=mysql_fetch_array($result)) {
echo "<div id='blog'><h1>". $row['title']. "</h1><p>". $row['content']. "</p>". "<br /><h6>Post On: ". $row['date']. "</h6></div>";

Can anyone help me? I would greatly appreciate it.

Share this post

Link to post
Share on other sites
I don't know what column you're using for your date stamp, but just change "date" below to what you have for your date column.

$result = mysql_query("SELECT * FROM blog ORDER BY date") or die(mysql_error());

Share this post

Link to post
Share on other sites


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.