Jump to content

Order by $month and $year


dpedroia

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.