SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ordering FROM_UNIXTIME?

    Ok, I have a script that pulls out the UNIXTIME date from a table, and then groups all messages by month as shown here.

    The problem as you can see is that it orders the MONTH Alphabetically. I obviously would like to keep them in the order (Jan, Feb, Mar, etc.). Can this be accomplished? I'm weak on PHP/Mysql, so the more help the better. Thanks.



    PHP Code:
    $result mysql_query("SELECT FROM_UNIXTIME( timestamp, '%Y - %M' ) AS get_month, FROM_UNIXTIME( timestamp, '%Y%m' ) AS get_month2, COUNT(*) AS entries FROM table GROUP BY get_month");

    while (
    $row mysql_fetch_array($result)) {
    $get_month $row["get_month"];
    $get_month2 $row["get_month2"];
    $entries $row["entries"];

    echo 
    "<a href=\"$link?month=$get_month2\">Entries from $get_month</a> ($entries)<br />";


  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... GROUP BY get_month ORDER BY get_month

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by firepages
    ... GROUP BY get_month ORDER BY get_month
    If only it was that easy, it is not.

    Actually found out the best way to do this is to SELECT the field ORDER it then, and use the date() function to convert it afterwards.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •