Answer the question
In order to leave comments, you need to log in
How to remove duplicate blocks with the interlocutor?
Good day to all! Please tell me how to display a block for each dialogue, so that the opposite combinations of interlocutors are not repeated.
The code itself:
$dialogs = mysql_query("SELECT *,COUNT(id) as count FROM `messages`
WHERE `from` = '$my_id' OR `to` = '$my_id'
GROUP BY `to`,`from` ORDER BY `date` DESC") or die(mysql_error());
while ($row = mysql_fetch_assoc($dialogs)) {
$my_id = $user_data['user_id'];
if($my_id === $row['to']) {
echo "mnie";
$to_me = '1';
$to_id = $row['from'];
?>
<?php
}if($my_id != $row['to']) {
echo "nie mnie";
$not_to_me++;
$to_id = $row['to'];
}
?>
<a href='?to=<?php echo $to_id;?>' style='text-decoration:none;'>
link
</a>
<?php
echo $row['from'];
echo "->";
echo $row['to'];
echo "<br>";
}
?to=$id
I get to the page, to the correct dialog. I am number 7. Answer the question
In order to leave comments, you need to log in
Perhaps this is a chat test case. First implementation.
What did you want to show in the message list? All the messages that someone wrote to someone? Then it works correctly. The counter is just not used and for some reason the table has a dialog_id, but you don’t use it either, but instead group by from + to.
For convenience, I would visually build the chat in a different way.
Look at this mockup https://icons8.com/2015/07/17/icons8-wpf-ui-framework/ , or rather, this screen take.ms/5F5rr
On the left side is a list of contacts to whom you recently wrote or who replied you.
To build it, you need such a request
SELECT DISTINCT A.`user_id`
FROM(
SELECT m1.`from` as `user_id`, m1.`date` FROM `messages` m1 WHERE m1.`to` = 7
UNION
SELECT m2.`to` as `user_id`, m2.`date` FROM `messages` m2 WHERE m2.`from` = 7
ORDER BY `date` DESC
) A
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question