Displaying Messages from the database

Hello There,

I have two tables.
Users - user_id ,user_name;
Messages - chat_id,user_id,chat_message.

I want to display messages of a particular user.How could I do that?Any suggestion?

First you have to get the messages that you want to display from the database table. How far have you gotten with this? Do you have any code that you can show us so that we can help you out?

Here I tried this.

First retrieved all the messages…

if ($stmt = $this->conn->prepare("SELECT `chat_id`,`chat_user_id`,`chat_message` FROM `message` ORDER BY `chat_id` DESC")) {
            $stmt->execute();
             $stmt->bind_result($chat_id, $chat_user_id, $chatmessage);
 while ($stmt->fetch()) {
 echo "message  is:". $chatmessage ."<br/>";
            }

Now it is displaying all the messages… How can I get the messages of a particular user.

You need a WHERE caluse to only select those from a certain user ID. WHERE user_id = :uid

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.