www.webdeveloper.com
Results 1 to 3 of 3

Thread: order by datetime / join

  1. #1
    Join Date
    Oct 2004
    Location
    Portland, OR
    Posts
    145

    order by datetime / join

    Hi,

    I have recently learned how to join tables in queries with mysql.
    But, like anything new, I am running into some problems.
    I would like the results to be sorted by datetime, but for some reason they are sorted in random order. I have listed the queries that I am using below with a link to a page where you can see the results of each query.
    s.date2 = (datetime) opening date
    s.close = (datetime) closing date

    Query: random order (joined)
    http://www.blackmarketculture.com/events/on_display.php
    Code:
    SELECT * 
    FROM galleries g,shows s
    WHERE
    g.gallery_id = s.gallery_id AND
    UNIX_TIMESTAMP('".$today."') >= UNIX_TIMESTAMP(s.date2) AND 
    UNIX_TIMESTAMP('".$today."') <= UNIX_TIMESTAMP(s.close)
    ORDER BY 's.date2'
    Query: ordered by datetime (no join)
    http://www.blackmarketculture.com/ev...ay_no_join.php

    Code:
    SELECT * 
    FROM shows
    WHERE
    UNIX_TIMESTAMP('".$today."') >= UNIX_TIMESTAMP(date2) AND 
    UNIX_TIMESTAMP('".$today."') <= UNIX_TIMESTAMP(close)
    ORDER BY 'date2'
    Thank you for your time,
    -Mike

  2. #2
    Join Date
    Jun 2004
    Posts
    390
    Hi Mike, try removing the quotes around your date fields in your ORDER BY statement.

  3. #3
    Join Date
    Oct 2004
    Location
    Portland, OR
    Posts
    145

    Thank you

    schizo,

    Yep that was the culprit...
    Thank You.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles