Jump to content

Recommended Posts

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.

$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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.