Log in

View Full Version : Data-base order on website



Timms
05-26-2012, 10:36 AM
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

guelphdad
08-03-2012, 04:32 AM
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.