I am having trouble with changing over some code from old style mysql queries to being prepared. I assume the problem is due to the fact that I'm using multiple whiles which each have their own query in which is causing problems cause only one prepared statement can be active at a time.
EDIT: If anyone cares, I've made it work with only 2 loops like so -
function createDeskMenu()
{
global $bookingTimes, $dbconn;
$day0 = mktime(0, 0, 0, date("m") , date("d"), date("Y"));
$query = "SELECT location FROM location";
$result = mysqli_query($dbconn,$query);
mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result))
{
$location = $row['location'];
echo "<h3>$location</h3><div>";
$query = $dbconn -> prepare("SELECT COALESCE( CountDesk, 0 ) total, name, d.desk_id, phone, fax, dock, pc FROM desk d LEFT JOIN (SELECT COUNT(booked.desk_id) CountDesk, desk_id FROM booked WHERE booking_id >=?)b ON d.desk_id = b.desk_id WHERE location=?");
$query->bind_param("is",$day0, $location);
$query->execute();
$query->bind_result($totalCount,$name,$desk_id,$phone,$fax,$dock,$pc);
while($query->fetch()) {
$total = count($bookingTimes) * 14 - $totalCount;
echo '<a href="?page=desk&desk='.$desk_id.'"><div class="desk"><b>'.$name.'
('.$total.' Available Bookings)</b><li>Facilities:';
if($phone){echo " Phone,";}if($fax){echo " Fax Machine,";}if($dock){echo " Laptop Dock.";}if($pc){echo " Desktop Workstation.";}
echo '</li></div></a><hr />';
}
$query->close();
echo '</div>';
}
}