交叉删除邮件

时间:2013-10-30 22:48:51

标签: php mysql mysqli messaging

我已经构建了非常简单的消息传递系统,但是我有一点问题。 当向表中插入新消息时,我将该消息与发送它的用户名相关联,并且当发送消息的用户删除该消息时,该消息也将从接收者中删除。

我希望只从发件人中删除邮件。我更新表并在执行实际删除之前将消息首先设置为deleted = 'yes'。有人能暗示我一个想法吗?

表格结构

id,from_user,to_user,subject,message,deleted,sent,date

$delete =$mysqli prepare("update messages set deleted = 'yes' where from_user = ?  and id = ? ");
$delete->bind_param('ss', $username->username, $id);
 foreach  ($_POST['id'] as $id) {
$delete->execute();

实际删除...

$stmt = $mysqli->prepare("DELETE  FROM messages where from_user = ?  and id = ?  or to_user = ? and id = ?");
$stmt->bind_param('ssss', $username->username, $id, $username->username, $id);
 foreach  ($_POST['id'] as $id) {
$stmt->execute();

1 个答案:

答案 0 :(得分:0)

简单的想法:p

需要的表格:

消息

id,content,lastmodified_time

MessageUser

id,UserId,MessageId,DeliveryType,Deleted

即:

<强>消息:

1,Test Message,2013-10-31 00:00:00

<强> MessageUser

1,11999,1,'外向',0

2,12585,1,'传入',1