I have created mysql databse based internal messaging system. In my DB structure there is table for messages in which each message have the sender user_id and receiver user_id. A inbox of any user can populate according to their own id relation as receiver_id in messages table. My problem is when I try to delete any message, so that message are gone from both the end sender & receiver. So is there any alternate solution in which the message is removed from only those user who performed the delete operation.
Here is my table structure for messages table:
Asked
Active
Viewed 1,266 times
2

sangam
- 171
- 2
- 4
- 13
-
Maybe two more columns called date_delete_sender and date_delete_receiver. Normally at null, if != null those are deleted and you can know when with a datetime field (example) or timestamp (example). You can also use a flag int(1) instead – Marco Mura Dec 18 '14 at 10:34
-
What do you use \`status\` for? – Strawberry Dec 18 '14 at 11:49
2 Answers
3
Add two more fields in the DB table:
deleted_by_sender
deleted_by_receiver
What needs to do with these?
The fields are self-explanatory.
Cheers:)

Pupil
- 23,834
- 6
- 44
- 66
-
1In inbox after reply on message sent by me is also display in inbox, means in the inbox there is messages which is send by other users and also send by me. when I try to delete multiple messages at a time then how I compare each message with current user is sender of that message or receiver and how can I update the flag to respective fields i.e deleted_by_sender and deleted_by_receiver. – sangam Dec 18 '14 at 10:47
2
when you are deleting the msg then you have to do some thing like that,you should have user_id who is deleting the msg.then you have to query that msg first to check that whether the msg is deleted by a sender or receiver. eg
$result = mysql_query("select sender,reciver from tbl_messages where msg_id='$msgid'");
$r = mysql_fetch_array($result);
$s = $r['sender'];
$r = $r['reciever'];
if($s==$user_id)
$st = "sender";
else if($r==$user_id)
$st = "reciever";
mysql_query("update tbl_messages set $st=0 where msg_id='$msgid'");
Note :I assumed that you are showing the msgs according to the sender and reciever id. It is just an example(errors and omissions are expected).hope it will help you.

Debugger
- 491
- 4
- 21