SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Primary and secondary sorting with MySql

    i know that i can sort by using order by, but when i tried 2 fields, it didn't sort like primary:secondary, just did them both as primary.
    so say i have 2 fields date_added and time_added.
    i want it to sort by the day added, and then the time.
    i have the field types for date_added as date, and time_added as time.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  2. #2
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I *THINK* that you can use:-

    SELECT FROM..........ORDER BY date_added ASC, time_added ASC

    but I'm not sure. Give it a go and I'll do some more checking up.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Defender, can you show us the sql you tried - because my tired head can't see why what KMxRetro has suggested wouldn't work - but I always have to test these things out because I can never remember. You could also try throwing in a GROUP BY on your primary order by field - that might help (GROUP BY must come before ORDER BY).

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hadn't got a chance to test what he posted.
    that worked fine.
    thx dude.

    this is what i WAS using:
    SELECT * FROM gallery_pics order by date_added,time_added DESC LIMIT $limitvalue, $limit

    and so i guess it was sorting both of them as primary.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •