alexcrosson Posted September 30, 2006 Share Posted September 30, 2006 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:[code]<?php $host = "localhost"; $user = "***"; $pass = "****"; $database = "*****"; $conn = mysql_connect($host,$user,$pass) or die ("Unable to connect to Database"); mysql_select_db($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>"; }?>[/code]Can anyone help me? I would greatly appreciate it. Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/ Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 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()); Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/#findComment-101599 Share on other sites More sharing options...
alexcrosson Posted September 30, 2006 Author Share Posted September 30, 2006 I used date as my column name and it doesn't work??? This sucks i'm lost. Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/#findComment-101607 Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 $result = mysql_query("SELECT * FROM blog ORDER BY date ASC") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/#findComment-101608 Share on other sites More sharing options...
alexcrosson Posted September 30, 2006 Author Share Posted September 30, 2006 Wait do you mean column or row? Or are they the same thing? Sorry I'm kinda noob to PHP and MySQL. Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/#findComment-101610 Share on other sites More sharing options...
extrovertive Posted September 30, 2006 Share Posted September 30, 2006 column/field in your table Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/#findComment-101618 Share on other sites More sharing options...
alexcrosson Posted September 30, 2006 Author Share Posted September 30, 2006 Alright I got it to work properly. All i had to do was change the ASC to DESC to get the effect I wanted. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/22618-sort-by-date/#findComment-101625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.