显示两个php用户之间的所有对话


showing all conversation between two users php

我正在尝试显示两个用户之间的对话,我有view.php,在那里我显示消息,我在该页面上还有回复按钮。我不知道如何将数据插入现有的消息行并显示所有对话。谢谢你的帮助。

我的表格结构:

         id
         from_user
         to_user
         deleted
         message
         date

view.php

 $user = 'currentuser';
 $reply = $_POST['relpy'];
 $id = $_GET['id']; 
 if (isset($_POST['replyto']))
 $reply = $_POST['reply'];  {
 if(!empty($reply)){

 $mydb = new mysqli('localhost', 'root', '', 'db');//this is where I am stuck I am using update so if I hit reply the existing data in the row will be overwritten.
 $stmt = $mydb->prepare("update  messages set message = ? where from_user = ?  and id = ? ");
 echo $mydb->error;
 $stmt->bind_param('sss', $reply, $user, $id);
$stmt->execute();

}
}
 if(!empty($id)){
 $mydb = new mysqli('localhost', 'root', '', 'db');
 $stmt = $mydb->prepare("SELECT * FROM messages where from_user = ?   and id = ? ");
 $stmt->bind_param('ss', $user, $id);
 $stmt->execute();
}

如果我理解正确,您希望NOT在这些用户/对话之间插入另一行,但用其旧值加上新值更新当前行(消息字段)。

IMHO这是一个糟糕的实现,需要额外的数据处理工作,但如果您将更新查询更改为:,则可以做到这一点

update messages set message=concat(message,?)其中from_user=?id=?