Как присоединиться к скрипту count в PHP mysqli
I have one problem I have added unread count filed to my script After display like this message Fatal error: Call to a member function get_result() on boolean in C:\xampp\htdocs\demo\npm\cons.php on line 110 I have added line
(SELECT from_id, COUNT(*) unread FROM pm WHERE to_id=? AND read='0' GROUP BY from_id) my problem here SELECT from_id, I want to add it counting one by one users unread messages showing i want to know to add it to my script. my database pm table id from_id to_id msg sent_date read 1 2 3 hi how are you? 2019-12-05 04:14:20 1 2 3 2 fine 2019-12-05 05:15:58 0 3 2 3 hi 2019-12-05 03:20:34 1 4 5 2 hi 2019-12-05 08:30:40 0 users table userid username 2 previn 3 rajesh 5 raj Here is my source code <?php if (isset($_SESSION['userid'])) { $session_id = $_SESSION['userid']; } $sql = "SELECT *, (SELECT username FROM users WHERE userid=from_id) AS from_username, (SELECT username FROM users WHERE userid=to_id) AS to_username, (SELECT username FROM users WHERE userid=?) AS my_username, (SELECT from_id, COUNT(*) unread FROM pm WHERE to_id=? AND read='0' GROUP BY from_id) FROM pm WHERE from_id = ? or to_id=? ORDER BY id DESC"; if ($stmt->prepare($sql)) { $stmt->bind_param('iiii', $session_id, $session_id,$session_id,$session_id); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { echo $row['from_username'] . " -> " . $row['to_username'] . "<br>"; echo 'User ' . $row['from_id'] . ' - ' . $row['unread']; } } ?>
Что я уже пробовал:
&низкотемпературный;
I have added line <code><pre> (SELECT from_id, COUNT(*) unread FROM pm WHERE to_id=? AND read='0' GROUP BY from_id)
Wendelius
Не могли бы вы подробнее рассказать, каков будет ожидаемый результат запроса на основе приведенных в примере данных?
Wendelius
Да, это сообщение об ошибке оператора, но что должен возвращать оператор SQL?