Results 1 to 4 of 4

Thread: Mysql Order by

  1. #1
    Join Date
    Feb 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Mysql Order by

    Hey,

    In mysql can you order items by when they were last updated?
    like

    Code:
    $last_updated = mysql_query("SELECT id,name,email,status FROM user WHERE status = 'online' ORDER BY ");
    What would I put order by to get the last updated ones first?

    Thanks

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,718
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    I'm pretty sure that you can't. You need to have a column that states when your entry was last updated and have that field updated every time you update that particular entry.

    Code:
    $last_updated = mysql_query("SELECT id,name,email,status FROM 
    user WHERE status = 'online' ORDER BY date2 desc");
    or something like that will work.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. The Following User Says Thank You to james438 For This Useful Post:

    Lemon (04-11-2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by james438 View Post
    I'm pretty sure that you can't. You need to have a column that states when your entry was last updated and have that field updated every time you update that particular entry.

    Code:
    $last_updated = mysql_query("SELECT id,name,email,status FROM 
    user WHERE status = 'online' ORDER BY date2 desc");
    or something like that will work.
    Yeh, I have a last edited field but it is day month year, I want it to be more precise like with minutes aswell otherwise it just orders the day in alphabetical order...

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Correct. So change how it stores the information. For reasons like this (just that generally it is more flexible) it's very common to use a timestamp instead of any formatted date. From that you can get a formatted date or use the timestamp as-is, such as for ordering.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    Lemon (04-11-2010)

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
  •