roytheboy Posted April 6, 2012 Share Posted April 6, 2012 Hi there, being a novice I am having problems showing files on my webpage in proper date order. They are stored in a mysql database. I have stored the files in a table called filestore which has 5 columns: ID = int column StoryDate = Varchar column fileName = Varchar column mimetype = Varchar column description = Varchar column filedata = mediumblob column The dates look like this: 8-November-2011, 21-March-2012 etc. and when drawn from the database they are formatted by an external file 'date.php' to look like this: 08-11-2011, 21-03-2012 etc. I tried to order by date DESC. Below is a snippet of the code: // Default page view: lists stored files $sql = 'SELECT id, filename, mimetype, storydate FROM filestore ORDER BY filestore.storyDate DESC, filestore.ID LIMIT 60'; $filelist = @mysql_query($sql); if (!$filelist) { exit('Database error: ' . mysql_error()); } ?> I wonder could the problem be that 'StoryDate' Varchar column is the wrong type? should it be Date or something else? The webpage in question is here: http://www.sercweb.com Any help greatly appreciated! Roytheboy. Quote Link to comment https://forums.phpfreaks.com/topic/260447-help-need-to-show-files-in-database-by-date-order-on-webpage/ Share on other sites More sharing options...
Muddy_Funster Posted April 6, 2012 Share Posted April 6, 2012 Why would you think to store dates as anything other than a date datatype? Best way to fix your problem is to fix your data. Quote Link to comment https://forums.phpfreaks.com/topic/260447-help-need-to-show-files-in-database-by-date-order-on-webpage/#findComment-1334921 Share on other sites More sharing options...
roytheboy Posted April 6, 2012 Author Share Posted April 6, 2012 I guess as I am typing in the dates pertaining to the event instead of them being automatically generated I assumed this might be stored as text (Varchar)? Thanks for pointing this out! Would I have to input this in a particular format? I have been using eg. 12-November-2012 Please excuse the novice in me. RTB Quote Link to comment https://forums.phpfreaks.com/topic/260447-help-need-to-show-files-in-database-by-date-order-on-webpage/#findComment-1334935 Share on other sites More sharing options...
roytheboy Posted April 6, 2012 Author Share Posted April 6, 2012 Thanks Muddy_Funster, did as instructed and now works! RTB. Quote Link to comment https://forums.phpfreaks.com/topic/260447-help-need-to-show-files-in-database-by-date-order-on-webpage/#findComment-1334946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.