這是我在屏幕上顯示的錯誤。參數錯誤PHP
警告:mysqli_fetch_assoc()預計參數1被mysqli_result,在/home/mjcrawle/onlinebanking/viewaccounts.php空給出線52
我覺得我的錯誤可能是在我的while循環不能確定。不過,我認爲我的代碼的構造是正確的。
<?php
/*Accounts*/
$currentMember->connection = $conn;
$accounts = $currentMember->retrieve_all_accounts();
/*Loop thorugh account - Grabs data*/
while($account = mysqli_fetch_assoc($accounts)){
/*Retrieve Balance*/
$bankaccount = new Bankaccount($account['BankAccountID']);
$bankaccount->connection = $conn;
$balance = mysqli_fetch_assoc($bankaccount->retrieve_current_balance());
echo '<tr>' . "\n";
echo "\t" . '<td>' . $account['BankAccountID'] . '</td>' . "\n";
echo "\t" . '<td>$' . number_format($balance['CurrentBalance'], 2) . '</td>' . "\n";
echo '<tr>' . "\n";
}
/*Close DB*/
mysqli_close($db->connection);
?>
</tbody>
</table>
</div><!--End of main content-->
<?php
include(ABSOLUTE_PATH . 'footer.inc.php');
?>
</div><!--end of header-->
顯然你的'retrieve_current_balance'方法返回'null'。找出爲什麼。 – Jon 2012-04-07 16:52:53
你確定它在'while'循環嗎?當我在急着調試時,我總是使用'die()',並帶有一條消息說明它在哪裏(即「我在while循環之前!」)。你可以使用'instanceof'類型操作符(http://php.net/manual/en/language.operators.type.php)來確保'$ accounts'和'$ bankaccount-> retrieve_current_balance()'是'mysqli_result'類。 – 2012-04-07 16:56:42