Skip to content
Advertisement

php query function repeating data

I am trying to make a facebook style chat page using php and mysql. But i have a problem with my query result. The chat table looks like this.

enter image description here

And i write this function for getting the message for loged in user.

and the foreachloop for getting result

So the problem is my query repeating the messages like the following screenshot also the query not showing loged in user messages.

To be a little more descriptive:

The query showing $toid = '3'; messages with repeat and not showing $logedInUserID = '2'; from data.

What is the problem in my query:

enter image description here

Advertisement

Answer

In given query it seems that you are trying to fetch details from two table User and Chat, however you have not written join condition.

Please try this SQL query, with $logedInUserID = ‘2’; $toid = ‘3’;

If you want entire chat with both user just use “OR” condition in Sql query with interchanged $logedInUserID = ‘3’; $toid = ‘2’

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement