Why does not one is a prepared statement inside another?

I have prepared statements and do any other have not yet closed it. I need to execute the expression inside it.
<?php
 $sql_sale_item = 'SELECT `id`,`name`,`price`,`old_price`,`img` FROM `shops` WHERE `sale` --> 0';
 $stmt_sale = $connection->prepare($sql_sale_item);
$stmt_sale->execute();
 $stmt_sale->bind_result($id, $name, $price, $old_price, $img);
 while ($stmt_sale->fetch()):
// Here I take data and I need to perform another query...
<?php endwhile; $stmt_sale--->close();?>

Request you want to release?
$raiting_check_sql = 'SELECT AVG(`assessment`) FROM `assessments` WHERE `product_id` = ?';
$raiting_check = $connection->prepare($raiting_check_sql);
$raiting_check->bind_param('i', $id);
$raiting_check->execute();
$raiting_check->bind_result($assessments);
$raiting_check->fetch();
$raiting_check->close();

Error:

Fatal error
: Uncaught Error: Call to a member function bind_param() on boolean in D:\OSPanel\domains\localhost\pages\index.php:27 Stack trace: #0 D:\OSPanel\domains\localhost\index.php(73): include() #1 {main} thrown in
D:\OSPanel\domains\localhost\pages\index.php
on line
27
June 3rd 19 at 19:23
2 answers
June 3rd 19 at 19:25
Solution
Because in the same connection it is impossible to open a second request not yet closed the cursor of the first query.
You can force to select all lines in the buffer using mysqli_store_result, then the first request will be considered complete.
June 3rd 19 at 19:27
Because it is not working.
If the circuit principle open another connection.

If not I would request 2 of the collected data. But if no load - so even one with joinem.

Find more questions by tags PHP