";对非对象上的成员函数fetch_assoc()的调用;当代码出现多次时出错


"Call to a member function fetch_assoc() on a non-object" error when the code appears more than once

如果我想在一个页面上使用此代码两次或两次以上(稍作修改),我会收到以下错误消息:

"调用非对象上的成员函数fetch_assoc()"

导致问题的代码行是:

while(($array_results[] = $results->fetch_assoc()) || array_pop($array_results));

代码已满如下:

<?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();
?>

如何修改它以防止错误消息出现,并防止此代码(稍微修改)在我的源代码中出现多次?我们一如既往地感谢您的帮助。

<?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()) 
{
    $client_id=$array_results['client_id'];
    $client_org_name=$array_results['client_organisation_name'];
    ?>
    <div class='dashDropdown'>
        <a href="create-a-property-2.php?client=<?php echo $client_id;?>" class="dashPropertyClientHover">
            <?php echo $client_org_name;?>
        </a>
        <?php echo "<br>";?>
    </div>
    <?php echo "<br>";?>
<?}
$results->close();
$mysqli->close();
?>