Jump to content


Photo

Sort By Date


  • Please log in to reply
6 replies to this topic

#1 alexcrosson

alexcrosson
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 30 September 2006 - 09:44 PM

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:
<?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>";
	}
?>

Can anyone help me? I would greatly appreciate it.



#2 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 30 September 2006 - 09:50 PM

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());

#3 alexcrosson

alexcrosson
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 30 September 2006 - 10:13 PM

I used date as my column name and it doesn't work??? This sucks i'm lost.

#4 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 30 September 2006 - 10:14 PM

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

#5 alexcrosson

alexcrosson
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 30 September 2006 - 10:18 PM

Wait do you mean column or row? Or are they the same thing? Sorry I'm kinda noob to PHP and MySQL.

#6 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 30 September 2006 - 10:43 PM

column/field in your table

#7 alexcrosson

alexcrosson
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 30 September 2006 - 11:01 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users