1

2 人のユーザー間の会話を表示しようとしています。メッセージを表示する 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();
}
4

1 に答える 1

0

私が正しいと理解した場合、これらのユーザー/会話の間に別の行を挿入したくないが、現在の行 (メッセージ フィールド) を古い値と新しい値で更新します。

IMHOこれは、データ処理に余分な作業を伴う悪い実装ですが、更新クエリを次のように変更すると実行できます。

更新メッセージ set message = concat(message, ?) where from_user = ? id = ?

于 2013-08-17T18:46:52.843 に答える