Epicballzy Posted September 28, 2014 Share Posted September 28, 2014 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! Quote Link to comment Share on other sites More sharing options...
trq Posted September 29, 2014 Share Posted September 29, 2014 ORDER BY fld DESC Quote Link to comment Share on other sites More sharing options...
Epicballzy Posted September 29, 2014 Author Share Posted September 29, 2014 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 } Quote Link to comment Share on other sites More sharing options...
trq Posted September 29, 2014 Share Posted September 29, 2014 There is no ORDER BY clause in that code. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 29, 2014 Share Posted September 29, 2014 Where is the order by? Quote Link to comment Share on other sites More sharing options...
Epicballzy Posted September 29, 2014 Author Share Posted September 29, 2014 (edited) 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 September 29, 2014 by Epicballzy Quote Link to comment Share on other sites More sharing options...
Frank_b Posted September 29, 2014 Share Posted September 29, 2014 what field type did you use to store the date in your database? it should be a date or datetime type. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 29, 2014 Share Posted September 29, 2014 I'm guessing that you have an sql error. Date is probably a reserved word. Enclose it in back-ticks. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 29, 2014 Share Posted September 29, 2014 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: ACTION BIT DATE ENUM NO TEXT TIME TIMESTAMP Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.