Jump to content

Retrieveing data from a database and reporting it to tabel


mlj0102

Recommended Posts

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

?>

 

 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.