Advanced Search

Results 1 to 2 of 2

Thread: Data-base order on website

  1. #1
    Join Date
    May 2012
    Location
    Wales UK
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Data-base order on website

    I have a mysql database which is displayed on my site with the fields in the DB being Date which is the date of the event, Location which is where the event will be held and the ID which is for admin purposes only... I also added an altdate which is specificly for ordering the display of the DB on the site which in the mysql DB is altdate. I insert this using the date format d-m-y, but im not getting the correct order of how it displays on the site when i re-order it on the site

    SELECT * FROM $tbl_name ORDER BY `altdate` ASC

    If i add some to the events from the month of may and then add some from the month of june then the ones for the month in june will go above some of the events that happen in may because of the date of that month if you see the image here

    http://www.chulse.co.uk/date-error.png

    you can see 1st of june has gone above 2 events that happen in may when i need the one in june to be at the bottom because it is the furthest away.

    Any help would be appriciated! Thanks

  2. #2
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Timms View Post
    I insert this using the date format d-m-y, but im not getting the correct order of how it displays on the site when i re-order it on the site
    If you are inserting your dates in that format then you are using CHAR or VARCHAR for your column type.

    Instead use DATE type for the column and insert as yyyymmdd and then use DATE_FORMAT when you pull the dates if you need them to appear in a different way.

    Problem solved.

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
  •