doforumda Posted October 19, 2009 Share Posted October 19, 2009 i want to select data from db order by date column and display the latest post first $query = "SELECT * FROM jobs_uni limit $start, $per_page"; //echo $query; $result = mysql_query($query); how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/ Share on other sites More sharing options...
Philip Posted October 19, 2009 Share Posted October 19, 2009 ORDER BY date DESC? Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/#findComment-939471 Share on other sites More sharing options...
doforumda Posted October 19, 2009 Author Share Posted October 19, 2009 i already use that this way $query = "SELECT * FROM jobs_uni limit $start, $per_page ORDER BY date DESC"; and $query = "SELECT * FROM jobs_uni ORDER BY date DESC limit $start, $per_page"; both are not working Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/#findComment-939475 Share on other sites More sharing options...
cags Posted October 19, 2009 Share Posted October 19, 2009 $query = "SELECT * FROM jobs_uni ORDER BY date DESC LIMIT $start, $per_page"; Looks correct. But you might wish to put back ticks around the column name of date as I think it may be a keyword (`date`). Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/#findComment-939589 Share on other sites More sharing options...
Philip Posted October 19, 2009 Share Posted October 19, 2009 @OP: What "isn't working"? Do you get an error? If so, what is it? @cags: Date is not a reserved keyword that requires backticks. See here for the full list. MySQL allows some keywords to be used as unquoted identifiers because many people previously used them. ACTION, BIT, DATE, ENUM, NO, TEXT, TIME, TIMESTAMP Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/#findComment-939648 Share on other sites More sharing options...
cags Posted October 19, 2009 Share Posted October 19, 2009 Ahh I wasn't certain, which is why I said 'I think', thanks for the link though, that may come in helpfull. Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/#findComment-939674 Share on other sites More sharing options...
fenway Posted October 20, 2009 Share Posted October 20, 2009 @OP: What "isn't working"? Do you get an error? If so, what is it? @cags: Date is not a reserved keyword that requires backticks. See here for the full list. MySQL allows some keywords to be used as unquoted identifiers because many people previously used them. ACTION, BIT, DATE, ENUM, NO, TEXT, TIME, TIMESTAMP That doesn't mean they aren't keywords -- and they are poor choices for column names. Quote Link to comment https://forums.phpfreaks.com/topic/178182-need-help-in-order-by-clause/#findComment-940449 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.