Merge two SQL queries
You need to combine the following two SELECT into a single query to display messages from all users on a single page.
The first request shows messages only from friends - messages from other users who are not in the friends list are not visible.if(empty($this->pages)) {
$query = sprintf("SELECT * FROM `messages` USE INDEX(`news_feed`) LEFT JOIN `users` ON `users`.`idu` = `messages`.`uid` AND `users`.`suspended` = 0 WHERE (`messages`.`uid` IN (%s) AND `messages`.`page` = 0 AND `messages`.`group` = 0 AND `messages`.`public` != 0 %s%s) ORDER BY `messages`.`id` DESC LIMIT %s", $this->friendsList, $start, $from, ($this->per_page 1))
}
The second query shows the messages of all users, regardless of whether they are friends or not, but in this case, messages from friends in the post feed are not visible, and messages from the blocked user are displayed, which is an error.if(empty($this->pages)) {
$query = sprintf("SELECT * FROM messages, users WHERE users.suspended = 0 AND messages.group = 0 AND messages.public = 1 AND messages.public 0 AND messages.uid = users.idu %s %s ORDER BY messages.id DESC LIMIT %s", $start, $from, ($this->per_page 1))
}
25.02.2022 20:33