dpedroia Posted July 16, 2010 Share Posted July 16, 2010 I have a <table> on my webpage that lists upcoming events, all of which are pulled from a MySQL database. In the <table>, there is a cell called 'Date' that can be sorted to sort the upcoming events from soonest to longest away. The dates are output using the following method: <td>$month/$day/$year </td> .. This creates the format of 06/07/2010 for June 7, 2010, for example. My SQL query for organizing the table initially is: $query = "SELECT * FROM events ORDER BY `month` ASC"; My question is this.. is there a way to have the ORDER BY order my data in something like the following: $query = "SELECT * FROM events ORDER BY `month`,`day`,`year` ASC"; Let's say there were two dates in the table: 05/01/2010 and 07/05/2011 representing May 1, 2010 and July 5, 2011, respectively. I want the SQL query to initially order the data by month, day, and year. How it is now, dates are being sorted by month, but the years are not in order so the <table> is not truly outputting the soonest events first. View the table here: http://www.vyfx.com/sportaccess/browseevents.php (currently may only view properly in Chrome; fixing this soon I hope this makes sense, and please let me know if you'd like more information. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/207965-order-by-month-and-year/ Share on other sites More sharing options...
Mchl Posted July 16, 2010 Share Posted July 16, 2010 If you want soonest dates first, you need to order by year, month, day Quote Link to comment https://forums.phpfreaks.com/topic/207965-order-by-month-and-year/#findComment-1087168 Share on other sites More sharing options...
dpedroia Posted July 16, 2010 Author Share Posted July 16, 2010 If you want soonest dates first, you need to order by year, month, day D'oh, of course. Not sure how I didn't realize that Thank you, all's well. Quote Link to comment https://forums.phpfreaks.com/topic/207965-order-by-month-and-year/#findComment-1087169 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.