Sort not working right?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce W...1

    #1

    Sort not working right?

    My SQL statement isn't sorting right. I want to sort by date.

    The table called 'news' has five columns:
    id (autoincrement int)
    published (date)
    url (varchar)
    title (varchar)
    source (varchar)

    The dates in the published column look like this: 2003-05-27

    This the SQL statement (in PHP):
    $query = "SELECT DATE_FORMAT(pub lished,'%M %e, %Y') AS whatnot, url,
    title, source FROM news ORDER BY whatnot";

    The query result does not sort by the date. Can anyone tell me what's
    wrong?

    Thanks for your help.
  • Too Sexy

    #2
    Re: Sort not working right?

    I think, the sorting takes places on the whatnot column wich could be
    interpreted as a string, which has month before year, try ORDER BY
    published, this way the internal save UNIX-Timestamp should be sorted.

    "Bruce W...1" <bruce@noDirect Email.com> schreef in bericht
    news:3FAA6F77.6 7E13ED9@noDirec tEmail.com...[color=blue]
    > My SQL statement isn't sorting right. I want to sort by date.
    >
    > The table called 'news' has five columns:
    > id (autoincrement int)
    > published (date)
    > url (varchar)
    > title (varchar)
    > source (varchar)
    >
    > The dates in the published column look like this: 2003-05-27
    >
    > This the SQL statement (in PHP):
    > $query = "SELECT DATE_FORMAT(pub lished,'%M %e, %Y') AS whatnot, url,
    > title, source FROM news ORDER BY whatnot";
    >
    > The query result does not sort by the date. Can anyone tell me what's
    > wrong?
    >
    > Thanks for your help.[/color]


    Comment

    • Bruce W...1

      #3
      Re: Sort not working right?

      Too Sexy wrote:[color=blue]
      >
      > I think, the sorting takes places on the whatnot column wich could be
      > interpreted as a string, which has month before year, try ORDER BY
      > published, this way the internal save UNIX-Timestamp should be sorted.
      >[/color]
      =============== =============== =============== ========

      Yes that fixed it. Thanks so much!

      Comment

      Working...