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

?>

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.