I am trying to make a chat system using php,mysql and ajax. But i need help from you about a topic. 

In short, I will try to tell you how I try to do it.

I have created one table from database the name is **`chat_conversations`** and table rows are 

```
  `message_id` int(11) NOT NULL AUTO_INCREMENT,
  `from_user_id` int(11) DEFAULT NULL,
  `to_user_id` int(11) DEFAULT NULL,
  `message_text` varchar(5000) CHARACTER SET utf8 DEFAULT NULL,
  `message_created_time` varchar(11) NOT NULL DEFAULT '1524910573',
  `seen` enum('0','1') NOT NULL DEFAULT '0',
  `message_type` varchar(8) DEFAULT NULL,
  `user_ip` varchar(45) DEFAULT NULL,

```

The above table shows how to display messages. When people send messages to each other, the data will come out like this.

[![enter image description here](https://image.prntscr.com/image/vAoLXxZASqqCj8ezQ5Cvjg.png)](https://image.prntscr.com/image/vAoLXxZASqqCj8ezQ5Cvjg.png)

and the above rows will be different when other users join.So far, everything is very nice. 

The question I want to ask is: think you are the one with user id 2. And you wanted to see a list of all the people you were chatting with. How did you do that. What I meant to say was that I did not understand how I would uncover it. Because you will have more than one message with `to_user_id` `3` or other `to_user_id` `(4,2,9,12,45, ... ext.)`

How can I unearth the list of chat contacts. How do I write a query.

```
public function ChatUserList($logedInUserID){
    $logedInUserID = mysqli_real_escape_string($this->db, $logedInUserID);
    $ChatUserList = mysqli_query($this->db," how do i write a sql query WHERE from_user_id = '$logedInUserID' ") or die(mysqli_error($this->db));
    while($row=mysqli_fetch_array($ChatUserList)) {
        // Store the result into array
        $data[]=$row;
     }
     if(!empty($data)) {
        // Store the result into array
        return $data;
     }  
}

```

Please look at the screenshot for what i want to show exactly:

[![enter image description here](https://image.prntscr.com/image/fCz8fa24RWyAoOXwRXfqFw.png)](https://image.prntscr.com/image/fCz8fa24RWyAoOXwRXfqFw.png)