Jump to content

[SOLVED] Order by month


SkyRanger

Recommended Posts

Ok, this is what I have so far but not sure how to display the months in the right order:

 

SELECT users.*, office.* FROM users, office where id = omid and ostatus = 'Active' ORDER BY 'opdate' DESC $max


opdate holds the dates like:  

Apr 29 07
Apr 30 07
May 01 07

I stuck in June 01 07 to see what would happen and it messed up the order

May
June
April

I am trying to figure out how to put it into the proper order

etc...
June 01 07
May 01 07
April 30 07
April 29 07
Mar 31 07
etc...

Not sure if this is possible.  Don't really wanna have to change all of the dates manually from Month = May to Month = 05

The $max code is for my pagination

Link to comment
https://forums.phpfreaks.com/topic/49477-solved-order-by-month/#findComment-242566
Share on other sites

That is why I was hoping there was a simpler way for me to fix this without having to do that.

 

Honestly, having had to fix some messes similar to that you are facing, AndyB's suggestion will be much easier in the long run than trying to circumvent what the data types are meant to do. If you fix the problem now, rather than trying to quiet the noise and pretend the problem doesn't exist, your script will be much more efficient, and if you ever expand it, you'll be in a much better boat down the road.

Link to comment
https://forums.phpfreaks.com/topic/49477-solved-order-by-month/#findComment-242604
Share on other sites

Ok, I tried using the DATE_FORMAT() option that you mentioned.  Thought it looked easy enough.  Boy was I wrong..lol, especially when I am using the sql select syntax that I require.

 

Here is what I tried to do:

 

$query = "SELECT users.*, office.*, office.date_format('opdate','%b %e, %Y') FROM users, office where id = omid and ostatus = 'Active' ORDER BY 'opdate' DESC $max";
$result = mysql_query($query) or die ("Query failed");

You can probably figure out what the outcome was.  Not good...lol

 

What am I doing wrong there?

 

or should I just convert:

 

$row['opdate'];

Link to comment
https://forums.phpfreaks.com/topic/49477-solved-order-by-month/#findComment-242802
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.