我正在开发一个允许用户删除邮件的消息传递应用程序,下面是一个查询就是这样做,我想根据其ID选择一条消息,然后如果其收件人删除了该消息的人case是(to_id),user1delete列将更新为' 1'如果是发件人,则user2delete列将更新为1,以下是我想要集成到一个或更好的如何根据其ID选择消息并更新所选行?
$query = "Select subject ,id, to_id, from_id, user_from, message, time_sent FROM pm
WHERE id = $id";
$result = $db->query($query);
$query = "UPDATE pm SET user1delete = '1'
WHERE
CASE
WHEN to_id = $to_id
THEN from_id != $to_id
END";
$result = $db->query($query);
$query = "UPDATE pm SET user2delete = '1'
WHERE
CASE
WHEN from_id = $to_id
THEN to_id != $to_id
END";
$result = $db->query($query);
非常感谢帮助。
答案 0 :(得分:1)
感谢@Pala,而不是选择使用第一个查询,我必须做的包括下面的where子句的id是我的解决方案:
$query = "UPDATE pm SET user1delete = '1'
WHERE
CASE
WHEN to_id = $to_id
THEN from_id != $to_id
AND id = $id
END";
$result = $db->query($query);
//$result = $db->query($query);
$query = "UPDATE pm SET user2delete = '1'
WHERE
CASE
WHEN from_id = $to_id
THEN to_id != $to_id
AND id = $id
END";
$result = $db->query($query);