Jump to content

need advise/help with my query..


DanDaBeginner

Recommended Posts

I have this:

table name: message

Fields: message_id  |  recepient_id  |  sender_id  |  content  |  time_sent  |  read

        auto+increment          1                    2                hello!     

                                            2                    1                hi!           

                                            1                    3                kiss me!

                                            3                    1                sure!       

  -----------------------------------

now my question is how can I get the latest conversation between 2 and 1.. for example 1 is the user and if 1 is the latest sender of their

conversation it will display like this:

 

Message: welcome 1.

conversation with 2: hello! - by me

 

if 2 is the lates of their sender then it will display like this:

Message: welcome 1.

conversation with 2: hi!

Link to comment
Share on other sites

How about:

 

SELECT * FROM message WHERE recipient_id IN (1, 2) ORDER BY message_id DESC LIMIT 1

 

Or, order by time_sent, which should match message_id in ordering I presume.  Then you can check if the message was to 1 or 2 and display the appropriate output.

 

Is that what you wanted?

Link to comment
Share on other sites

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.