gpt4 book ai didi

PHP/MySQL SELECT 语句 - 小问题

转载 作者:行者123 更新时间:2023-11-29 09:22:34 26 4
gpt4 key购买 nike

我最近在我正在开发的私有(private)消息系统的 SELECT 语句中发现了一个漏洞。

这是我的表格的基本结构:

tblpm:
unique_id thread_id subject content receiver_id sender_id date_sent

我正在开发的页面是收件箱,其中为用户显示所有最新消息。

我使用的 SELECT 语句是:

$data = mysql_query("
SELECT tblpm.* FROM tblpm
WHERE date_sent
IN(
SELECT MAX(date_sent)
FROM tblpm
GROUP BY message_id
)
AND receiver_id ='$usrID'
ORDER BY id DESC") or die(mysql_error());

现在,这是我注意到的:当我第一次向用户发送消息时,它发送得很好,并且没有显示在收件箱中。 (因为它不应该,所以它应该显示在“已发送的项目”中)。然后,如果用户要“回复”该消息(因此,同一线程),它也会在收件箱中正常显示。

但是,如果我回复“回复”(换句话说,线程中的第三条消息),它就不再显示在收件箱中,因为 SELECT 语句被定向为选择 MAX(date_sent)一个线程,其中receiver_ID = $usrID。问题在于,最近的 (date_sent) 线程项正被其他人“接收”,因此 SELECT 语句不会显示“任何”线程项。

希望这是有道理的。

这是正在发生的事情的直观表示:

unique_id    thread_id    subject   receiver_id    sender_id     date_sent
1 144 Msg 22 33 2009-07-22 //Will display fine in sent items.
2 144 re: Msg 33 22 2009-07-23 //Will display fine in inbox of user (usrID 33).
3 144 RE: re:Msg 22 33 2009-07-24 //Once this message is sent, the entire thread (thread_id 144) no longer displays in the inbox.

对此的任何帮助将不胜感激!

最佳答案

看起来这应该做你想要的:

$data = mysql_query("
SELECT tblpm.* FROM tblpm
WHERE date_sent
IN(
SELECT MAX(date_sent)
FROM tblpm
WHERE receiver_id ='$usrID'
GROUP BY message_id
)
AND receiver_id ='$usrID'
ORDER BY id DESC") or die(mysql_error());

关于PHP/MySQL SELECT 语句 - 小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1185935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com