Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 一对一聊天_Php_Html_Css_Ajax - Fatal编程技术网

Php 一对一聊天

Php 一对一聊天,php,html,css,ajax,Php,Html,Css,Ajax,我正在尝试发展一对一的聊天。我希望用户只能看到来自发送者的消息,即发送者只能看到来自他自己和接收者的消息,但查询无法运行。我能够看到数据库中存在的所有消息 public function getMessages() { $messages = array(); $query = <<<QUERY SELECT `chat`.`message`, `chat`.`sent_on`, `user1`.`id`, `

我正在尝试发展一对一的聊天。我希望用户只能看到来自发送者的消息,即发送者只能看到来自他自己和接收者的消息,但查询无法运行。我能够看到数据库中存在的所有消息

public function getMessages() {

 $messages = array();
 $query = <<<QUERY
    SELECT 
      `chat`.`message`, 
      `chat`.`sent_on`,
      `user1`.`id`, 
      `user1`.`first_name`
    FROM `user1`
    JOIN `chat`
      ON `chat`.`user_id` = `user1`.`id` AND `chat`.`rec_id`=$recid
    ORDER BY `sent_on`
  QUERY;
公共函数getMessages(){ $messages=array();
$query=您需要在查询中指定
userId
,如下所示:

public function getMessages($userId) {

  $messages = array();
  $query = <<<QUERY
     SELECT 
       `chat`.`message`, 
       `chat`.`sent_on`,
       `user1`.`id`, 
       `user1`.`first_name`
     FROM `user1`
     JOIN `chat`
       ON `chat`.`user_id` = `user1`.`id` AND `chat`.`rec_id`=$recid
     WHERE `user1`.`id` = {$userId}
     ORDER BY `sent_on`
   QUERY;
公共函数getMessages($userId){
$messages=array();

$query=你的问题是什么?这里没有问题?
你无法解决。
但是什么。??这个问题看起来很像tbh。