I Built a 2D array which basically grabs information from a mysql database. The First While loop, loops through DB for info and unique IDs from some rows, works fine. The inner while loop then grabs info from another table when as certain condition is met, this is where I have the issue. I get issue when I use bind_param() inside the inner loop. I have minimized the code so all the irrelevant conditions and line aren't taking up the page.
Here is my error
Commands out of sync; you can't run this command now
Fatal error: Call to a member function bind_param() on a non-object
Here is the basics of my loops
function propertyFeedIndex($conn, $ListingAgentID)
{
$sql = "SELECT ListingID FROM mls_listings_phrets WHERE ListingAgentID = ? order by id desc";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $ListingAgentID);
$stmt->execute();
$stmt->bind_result($ListingID);
if($stmt->fetch()){
while($stmt->fetch()){
// Get Images
$sql_img = "SELECT C_PATH FROM mls_listings_images_phrets WHERE C_Matrix_Unique_ID = ? order by `id` asc";
$stmt_img = $conn->prepare($sql_img);
echo $conn->error;
$stmt_img->bind_param('s', $ListingID);
$stmt_img->execute();
$stmt_img->bind_result($C_PATH);
if($stmt_img->fetch()){
while($stmt_img->fetch()){
echo "Help Me " . $C_PATH;
}
}
}
}else{
echo "We Have Issues!";
}
return $finalArray;
}