kevinkhan Posted January 22, 2011 Share Posted January 22, 2011 $select = 'SELECT (YEAR(CURDATE())-YEAR(dateOfBirth)) - (RIGHT(CURDATE(),5)<RIGHT(dateOfBirth,5)) AS age'; $from = ' FROM profile_list'; $where = ' WHERE TRUE'; $order = ' ORDER BY age;'; $sql = $select.$from.$where.$order; Quote Link to comment https://forums.phpfreaks.com/topic/225313-how-come-this-query-wont-order-by-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2011 Share Posted January 22, 2011 how come this query wont order by date Well, you are ordering by age, which is not a date, and you also didn't post any information about what result you are getting and what your expected result should be. Quote Link to comment https://forums.phpfreaks.com/topic/225313-how-come-this-query-wont-order-by-date/#findComment-1163609 Share on other sites More sharing options...
Simon Mayer Posted January 23, 2011 Share Posted January 23, 2011 Well, you are ordering by age, which is not a date, and you also didn't post any information about what result you are getting and what your expected result should be. The above is correct, I suspect you would need to do the following: $order = ' ORDER BY `dateOfBirth`;'; You would do the following to reverse the order (youngest first): $order = ' ORDER BY `dateOfBirth` DESC;'; Quote Link to comment https://forums.phpfreaks.com/topic/225313-how-come-this-query-wont-order-by-date/#findComment-1164048 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.