I have an array populated with records from one table and want to count corresponding records from another table and insert that into the array.
When I try this code I keep getting this error
Warning: mysqli::prepare() [mysqli.prepare]: All data must be fetched before a new statement prepare takes place
foreach ($persons as $i=>$person)
{
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM order WHERE personId = ?");
$stmt->bind_param("i", $person['personId']);
$stmt->execute();
$stmt->bind_result($totalOrders);
$stmt->fetch();
$stmt->close;
$persons[$i]['totalOrders'] = $totalOrders;
}
It’s as though the $stmt->close; is being ignored.
You need to add parentheses to call the close method: