2017-04-18 122 views
-1

我正在嘗試開發一對一聊天工具。我希望用戶只能看到來自發件人的郵件,即發件人只能看到自己和收件人的郵件,但查詢無法運行。我能看到所有的數據庫中存在一對一聊天PHP

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; 
+0

你有什麼問題? –

+0

這裏沒問題嗎? – Akintunde007

+0

'你無法解決.'但是什麼?????** – Chirag

回答

0

您需要在您的查詢指定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;