Jump to content

Recommended Posts

I have a posting system worked out, as well as my database configured to my linking.. But as of right now, my posts are posted from oldest to newest, having users scroll down or go to the next page to see the most recent post.

 

How would I "flip" that around and make my posts start from newest to oldest by its date/time (Which is stored in the database)?

 

Thanks!

ORDER BY fld DESC

 

I have added the ORDER BY, but nothing has changed. The way I'm displaying the data, is using a while loop, gathering everything about the row in the database, and displaying select fields from an array. Would that have an affect on the ODER BY?

 

This is what I do:

$sql2 = mysql_query("SELECT * FROM posts $limit");//$limit if for my pagination
while($row = mysql_fetch_array($sql2)) {
					
	$post_data = $row;
				
	$title = $post_data['title'];
	$content = $post_data['content'];
	$author = $post_data['author'];
	$post_id = $post_data['post_id'];?>

        //Then I add the variable in divs/header tags
}

There is no ORDER BY clause in that code.

I was just stating that that's how I do it. Not with the ORDER BY.

Here's how I did it with the ORDER BY:

$sql2 = mysql_query("SELECT * FROM posts ORDER BY date DESC $limit"); 

DESC or no DESC.. It hasn't worked.

Edited by Epicballzy

I'm guessing that you have an sql error.  Date is probably a reserved word.  Enclose it in back-ticks.

Why guess when you can look it up?

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

 

 

MySQL permits some keywords to be used as unquoted identifiers because many people previously used them. Examples are those in the following list:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.