我正在开发一个私人消息系统,就像在一个简单的论坛网站中一样。但我不确定 SELECT 查询是否正确。
我试图在聊天框中显示每条消息,因此例如用户A向用户B发送了一条消息,而用户B可能向用户A发送了另一条消息。但我不断收到“问题”字符串(在 else 语句中,不会查询......)。
$alici = $_GET['user'];
$username = $_SESSION['username'];
$mesajlar = $con->prepare("SELECT * FROM messages WHERE sender_name=:s AND receiver_name=:r OR sender_name=:s2, AND receiver_name=:r2");
$mesajlar->execute([':s'=>$username, ':r'=>$alici, ':s2'=>$alici, ':r2'=>$username]);
if ($mesajlar->rowCount() > 0) {
foreach ($mesajlar as $mesajlar_each) {
$sender_name = $mesajlar_each['sender_name'];
$receiver_name = $mesajlar_each['receiver_name'];
$messsage = $mesajlar_each['message_text'];
if($sender_name == $username){
?>
<div class="grey-message">
<a href="#"> Me </a>
<p> <?php echo $message; ?> </p>
</div>
<?php
}
else{
?>
<div class="white-message">
<a href="#"> <?php echo $sender_name; ?> </a>
<p><?php echo $message; ?> </p>
</div>
<?php
}
}
}
else{
//problem
echo "problem";
}
?>
```
动漫人物