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
https://forums.phpfreaks.com/topic/40324-need-advisehelp-with-my-query/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.