I have to show messages thread of login users. Well Showing thread is not actually issue. I im facing trouble while showing all messages list. Requirement is as follow.
1) Messages List page (message_list.php): Only last message will display here that was being send or receive by login user. in that case login users can be sender or receiver. e.g
user "mahendra" is a login users. and had communication with many other users lets say John, Smith, Sandra. On message_list.php page only last message should be displayed within each user.
DB Structure is as follow:
id(pk),from_id,to_id,message
What should be a query for this ?
Assuming id for your current user is lets say 5
SELECT message FROM yourTable WHERE to_id=5 OR from_id=5 ORDER BY id DESC LIMIT 1