mlj0102 Posted April 29, 2012 Share Posted April 29, 2012 I am trying to echo out an array from my data base. I think I have my function created correctly: Noted below is the snippet from my transaction.class.php file <?php //Retreives data from the database public function retrieve_all_data($TransactionDate=0, $TransactionType=0, $TransactionAmount=0, $CurrentBalance=0){ $accounts_query = "SELECT TransactionDate, TransactionType, TransactionAmount, CurrentBalance FROM BankAccount, TransactionType, TransactionLog = " . $this->accountid ." LIMIT 0,30"; $result = mysqli_query($this->connection, $accounts_query); return $result; } ?> I try to echo out using this format but I am not having any luck. <?php /*Accounts*/ $currentMember->connection = $conn; $accounts = $currentMember->retrieve_all_data(); /*Loop through account - Grabs data*/ while($account = mysqli_fetch_assoc($accounts)){ /*Retrieve Balance*/ $transaction = new Transaction($account['TransactionDate'], $account['TransactionType']); $transaction->connection = $conn; //$balance = mysqli_fetch_assoc($transaction->retrieve_current_balance()); echo '<tr>' . "\n"; echo "\t" . '<td>' . $account['TransactionDate'] . '</td>' . "\n"; echo "\t" . '<td>' . $account['TransactionType'] . '</td>' . "\n"; echo '<tr>' . "\n"; } /*Close DB*/ mysqli_close($db->connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261815-retrieveing-data-from-a-database-and-reporting-it-to-tabel/ Share on other sites More sharing options...
xyph Posted April 29, 2012 Share Posted April 29, 2012 You seem to be lacking a WHERE clause. You should check if the query returns FALSE, which is returned when an error occurs in the query. You should also be coding with all error reporting turned on. http://php.about.com/od/troubleshooting/qt/php_error_reporting.htm You'd notice it throws an error, saying [m]mysqli_fetch_assoc[/m[ expects a resource, boolean given. This boolean value is probably FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/261815-retrieveing-data-from-a-database-and-reporting-it-to-tabel/#findComment-1341585 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.