If I want to use this code twice or more on a page (with slight modifications), I get the following error message:
"Call to a member function fetch_assoc() on a non-object"
The line of code which is causing the issues is this:
while(($array_results[] = $results->fetch_assoc()) || array_pop($array_results));
The code is full is as follows:
<?PHP
if($_SESSION['member_unique_id']=="supermember"){
$results = $mysqli->query("SELECT client_organisation_name, client_id FROM clients ORDER BY client_organisation_name ASC");
}
else{
$results = $mysqli->query("SELECT client_organisation_name, client_id FROM clients WHERE member_unique_id='".$_SESSION['member_unique_id']."' ORDER BY client_organisation_name ASC");
}
while(($array_results[] = $results->fetch_assoc()) || array_pop($array_results));
echo '<div class="dashDropdown">'."\n";
foreach($array_results as $client) {
echo '<a href="create-a-property-2.php?client='.$client['client_id'].'" class="dashPropertyClientHover">'.$client['client_organisation_name'].'</a>'."\n";
}
echo '</div>'."\n";
$results->close();
$mysqli->close();
?>
How can this be amended to prevent the error message appearing and for this code (modified slightly) to appear more than once in my source code? Any help as always is appreciated.