refiking Posted March 26, 2010 Share Posted March 26, 2010 I am trying to sort the results by (added) which is a timestamp, but it isn't sorting them by the timestamp. Some of the most recent entries (which should appear at the top) or going down to the middle. Here is the query: $sql = mysql_query("select * from records where `read` < 1 order by added"); Quote Link to comment https://forums.phpfreaks.com/topic/196629-what-is-wrong-with-my-query/ Share on other sites More sharing options...
jonsjava Posted March 26, 2010 Share Posted March 26, 2010 forgot to tell it how to order (ascending, descending) $sql = mysql_query("SELECT * FROM `records` WHERE `read` < 1 ORDER BY `added` ASC;") or die("ERROR, Will Robinson! Here it is:\n".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/196629-what-is-wrong-with-my-query/#findComment-1032369 Share on other sites More sharing options...
refiking Posted March 26, 2010 Author Share Posted March 26, 2010 I tried that, here's a few of the values I got: 2010-03-27 01:24:32 2010-03-26 01:39:00 2010-03-26 11:54:00 2010-03-27 12:23:48 2010-03-27 12:23:48 And that's the exact order they were displayed in... Quote Link to comment https://forums.phpfreaks.com/topic/196629-what-is-wrong-with-my-query/#findComment-1032375 Share on other sites More sharing options...
jonsjava Posted March 26, 2010 Share Posted March 26, 2010 might be better to store dates in unix timetamp. Easier to calculate. Quote Link to comment https://forums.phpfreaks.com/topic/196629-what-is-wrong-with-my-query/#findComment-1032377 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2010 Share Posted March 26, 2010 The default ORDER BY by is ASC. If the column is a mysql TIMESTAMP data type, what you are doing will work. What is the column definition and how did you produced and enter the values? Also, what is your code that is retrieving and displaying the results? Short-answer: There's nothing wrong with the method you are using and it should work, assuming the column, the data, and your code is what you are implying. Quote Link to comment https://forums.phpfreaks.com/topic/196629-what-is-wrong-with-my-query/#findComment-1032442 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.