私の最後の質問は非常に漠然としていたので、いくつかのことを明確にすることにしました。プライベート チャット アプリケーションの作成方法を学んでおり (教育上の理由のみ)、プライベート チャットを行う最善の方法を見つけようとしています。2 つのテーブルを作成しましuser
たchat
。にはchat
、5 つの列があります。
- message_id
- ユーザーID
- ユーザー名
- メッセージ
- 送信
選択した からメッセージのみを取得したいuser_id
。
今、ここに私の送信フォームがあります。入力名 send = 取得したいデータ。user_id
コツをつかむまでは、番号だけを取得したい(そのため、そのユーザー名とチャットするには、テキスト領域に番号を入力します)。
<form name="form" method="post">
<input type="text" name="send" id="send" value="">
<input name="user_id" type="hidden" value="<?php echo $_SESSION['user_id'];?>" id="user_id">
<textarea name="message" class="message" onkeydown="if (event.keyCode == 13) document.getElementById('submit').click()"></textarea>
<input type="submit" name="Submit" id="submit" value="">
</form>
そして、ここに私のphp検索フォームがあります
<?php
class Chat extends Core {
public function fetchMessages() {
$this->query("
SELECT chat.message,
users.username,
users.user_id,
chat.send
FROM chat
JOIN users
ON chat.user_id //and chat.send = users.user_id
ORDER BY chat.timestamp
DESC
");
return $this->rows();
}
}
基本的に、次のような条件を設定したいと思います。
<?php
$send=$_POST['send'];
$userid=$_POST['user_id'];
if ($send == $userid || (isset($_POST['user_id']))) //this isn't correct- just trying to display my though
{
//retrieve message from user_id number in sql table, allowing the people that have the same user_id as send to only read the message.
}
?>
基本的に、特定の user_id 番号の情報のみを取得するにはどうすればよいですか? また、この条件をどこに配置すればよいでしょうか?