私人消息数据库查询显示

时间:2012-11-06 15:16:42

标签: php mysql

好吧我在db中有这样的消息表:

id
thread_id
from_user
to_user
message

我遇到的问题是在网站上显示这些消息。与私人消息一样,只有接收者和发送者才能看到消息。还有一件事是重要的,消息与线程相关,所以当发件人联系创建线程的用户(用户只能向线程创建者发送消息时,每个被联系的用户必须有他创建的线程)这个对话是仅与此线程相关。所以,现在检查我尝试了什么:

SELECT * 
FROM messages 
WHERE thread_id = '$thread_id' 
    AND (from_user = '$from' OR from_user ='$to' ) 
    AND ( to_user = '$to' OR to_user = '$from' )

这适用于大多数情况,但我想知道的是,这是否是经典查询,用于仅限制用户查看邮件?

$thread_id is ID of the thread passed to query
$from is $_SESSION['id'] 
$to is ID of thread owner ( user who receives the message )

我用很少的用户对此进行了测试,但有些事情是不对的。有时我只收到一条发送的邮件,但看不到回复

0 个答案:

没有答案