There are 4 tables:
fandom - The name of the dialog group.
dialog - List of dialogs in the group.
dialog_users - Users in each group dialog.
chat - Messages in a specific dialog.
Task:
Display dialogs on the profile page in order (New above) + above new dialogs display those dialogs in which new messages have been added (Example as VK, Facebook).
Ready developments: There is a conclusion of dialogs. No sorting by posts.
Code of developments:
$sql_dialog = mysql_query(" SELECT `d`.*, (SELECT `f_title` FROM `fandom` WHERE `id` = `d`.fandom) AS `f_title` FROM `dialog_users` d WHERE `d`.users = '$_SESSION[id]' GROUP BY `d`.fandom ORDER BY `date` DESC"); while($dialog = mysql_fetch_assoc($sql_dialog)){ $array_dialog[] = $dialog['dialog']; } //Вывод сообщений по диалогам $sql_chat = mysql_query(" SELECT `dialog`,`text`,`status` FROM `chat` WHERE `dialog` IN (".implode(',',$array_dialog).") GROUP BY `dialog` ORDER BY `date` DESC"); while($chat = mysql_fetch_assoc($sql_chat)){ $array_chat[] = $chat['dialog']; } foreach(){ //Соединение обеих массивов }
It would be ideal to do all this in one request.
For this code, I don’t understand how to display the dialogues on new messages (the status field (1/0) in the chat table is responsible for this) and adding a condition, if status = 0, sort only by date .
If you have any idea how to finish this code, I would be immensely grateful for your help ...