[eluser]theprodigy[/eluser]
When a user sends a message:
1. input the message details into the Messages table (using logged in user_id for the 'from_id' field, and current date and time for 'sent' field)
2. get the input id from that record
3. for each recipient (if you allow more than 1), input the message_id (the one you got from step 2) and the user_id of the recipient (you may have to select the user_id from the database users table)
To list all messages in a user's inbox:
1. Select the subject, from_id, sent from the Messages table, join messages_sent table on message_id, where messages_sent.to_id = logged in user_id and messages_sent.deleted = 0
1a. Optionally select messages_sent.has_read if you want to bold the unread ones
To list all messages in user's trash:
1. same as above only messages_sent.deleted = 1
When a user clicks on a message to read it:
1. update messages_sent.has_read to 1, where message_id = the one they clicked on, and to_id = their id
2. select body, subject, from_id, sent from messages where id=message_id (where message_id = the one they clicked on).
When a recipient deletes a message from inbox:
1. update messages_sent.deleted to 1 where messages_sent.message_id = message_id and to_id = their id
when a recipient deletes a message from trash:
1. update messages_sent.deleted_from_trash where messages_sent.message_id = message_id and to_id = their id
When a sender deletes a message (from their sent box):
1. update messages.deleted to 1 where id = message_id and from_id = their id
I think that just about covers it. If I missed anything, I'm sure you should be able to figure it out by browsing through the instructions above and seeing how the tables are connected. If not, just ask (but please give it try first. It's not too difficult ;-) ).