Tonic-_- Posted November 24, 2009 Share Posted November 24, 2009 Well you know.. I been getting into mysql and it's quite interesting but now I have seem to of hit a bump in the road.. I am creating a private messaging system and wanted to display messages from last to first (in mysql it displays first to last). If you are lost then what I mean is I am of course generating a ID for each private message being created and saved into the database, now the problem is of course when you goto display messages sent to a specific username or ID it will display the first message you ever created and to last.. I want to reverse that and display most recent to last. If I can't get a simple answer for it I might just try doing time stamps and doing math conversions for the problem if it comes to it.. Any ideas? I'm sure this is a simple task that I am just overlooking. Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/ Share on other sites More sharing options...
mrMarcus Posted November 24, 2009 Share Posted November 24, 2009 $sql = " select `messages` from `message_table` order by `date` desc "; of course, change fields/table name, etc., to accommodate your table/query. EDIT: asc/desc is what you're looking for. order by is set to whatever you're ordering the table by .. can be date, id, etc. you can have multiple inputs. Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/#findComment-965025 Share on other sites More sharing options...
Tonic-_- Posted November 24, 2009 Author Share Posted November 24, 2009 Ahh so no matter what I have to use timestamps.. Ok, thanks a bunch. Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/#findComment-965032 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 well theoretically, if you were using an auto increment id, than ordering by that id should work also. Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/#findComment-965036 Share on other sites More sharing options...
Tonic-_- Posted November 24, 2009 Author Share Posted November 24, 2009 Well yeah i'm automatically incrementing each message ID but a time stamp is also good to notify the user when it was sent so thanks a lot. Is the solve option removed? I don't see it... Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/#findComment-965038 Share on other sites More sharing options...
mrMarcus Posted November 24, 2009 Share Posted November 24, 2009 ya, that was an example. order it by whatever you want so long as whatever you order it by, the results can be manipulated accordingly. for example, don't order the query by a value that every record has the same of. ordering by date is just a common one as you can easily determine the age of something by the date, right? as mikesta said, id might work best since it's being auto-generated by the db, therefore, you will always get the expected results. just because i say something, doesn't make it the final answer .. try things out for yourself. Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/#findComment-965039 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 Yes, the solved mod hasn't been reinstalled yet as of the new upgrade I believe. timestamps are never bad to have though, so you might just want to add it to your table anyways Quote Link to comment https://forums.phpfreaks.com/topic/182839-how-to-display-mysql-results-last-to-first/#findComment-965040 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.