Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...It is good to know that there are groups such as this willing to share knowledge in this money driven economy..."

Geography

Where in the world do Tek-Tips members come from?

I am a novice at PHP (at best) but Helpful Member!(2) 

novice60 (TechnicalUser)
27 Apr 12 14:51
I am novice at PHP and I am trying to use an array to pull data from different tables within a database.  Then to report that data to a form that i have created.  

I have created separate functions that pulls the data from the database.  Which they work because I can pull data when I set the array up to pull from only one table.

This is the array that I have to created.  I know this is wrong... probably not even close.  I can get it to work when pull the data one table but I am struggling to pull from multiple tables.

This is my connection and array to the DB.

<?php
    /*Accounts*/
    $currentMember->connection = $conn;
    $accounts = $currentMember->retrieve_all_accounts();
    
    /*Loop through account - Grabs data*/
    while($account = mysqli_fetch_assoc($accounts)){
        $transactionlog->connection = $conn;
        
        /*Retrieve Account data*/
        $transactionlog = new Bankaccount($account['BankAccountID'] );
                
        //Different table within that database
        $transactionlog = mysqli_fetch_assoc($transactionlog->retrieve_transactions());
        $transactionlog->connection = $conn;
        
        //Different table within the database
        //$transactionlog = mysqli_fetch_assoc($transactionlog->retrieve_transactiontype());
        
        echo '<tr>' . "\n";
        echo "\t" . '<td>' . $account['BankAccountID'] . '</td>' . "\n";
        echo "\t" . '<td>' . date($transactionlog['TransactionDate'] ) . '</td>' . "\n";        
        echo "\t" . '<td>' .  $account($transactionlog['TransactionType']) . '</td>' . "\n";
        echo "\t" . '<td>$' . $account($transactionlog['TransactionAmount'], 2) . '</td>' . "\n";
        echo "\t" . '<td>$' . number_format($balance['CurrentBalance'], 2) . '</td>' . "\n";
        echo '<tr>' . "\n";
        }
        
        /*Close DB*/
        mysqli_close($db->connection);
?>

 
Helpful Member!  vacunita (Programmer)
27 Apr 12 15:06
Looks like you have abstracted the actual query building.

You'd need to show us what your classes and their functions are doing.

Such as object currentMember and its method retrieve_all_accounts()

As a starting point it all comes down to how you build your queries.
So perhaps instead of abstracting single table queries, you can create a method that takes as parameters table names in an array even and builds queries based on that.  

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 

novice60 (TechnicalUser)
27 Apr 12 20:45
I have included class and my functions.  I do okay with SQL but PHP is a different world for me.  I am a Student...  I am not trying to get anyone to do my work for me.  However, I do want to learn this.

I have been working on this and now I am getting data from multiples tables but I am only getting data from one account.  and it is does display all the data.  I would like for it to display all the data.  

<?php
/*Bankaccount Class*/
class Bankaccount {
    
    /*attributes for the first and last name of the class*/
    private $accountid;
    private $memberid;
    private    $accounttypeid;
    private    $accounttypename;
    public     $connection;
        
    /*Constructs the function*/
    function __construct($accountid){
        $this->accountid = $accountid;
    } //end constructor
    
    /*Destroys the function*/
    function __destruct(){
    } //ends destructor
    
    /*Get funtion*/
    public function __get($name) {
        return $this->$name;
    } // Ends get funtction
    
    /*Use the set function*/
    public function __set($name, $value) {
        $this->$name=$value;
    } //End set function
    
    
    /*This is what retrieves the values from memmory*/
    public function retrieve_current_balance() {
        $balance_query = "SELECT CurrentBalance FROM BankAccount WHERE BankAccountID = " . $this->accountid . " LIMIT 0,1";
        
        $result = mysqli_query($this->connection, $balance_query);
        
        return $result;
    }
    //query for transactions
        public function retrieve_transactions() {
        $transaction_query = "SELECT CurrentBalance, TransactionType, TransactionAmount, TransactionDate FROM BankAccount, TransactionType, TransactionLog = " . $this->accountid . " LIMIT 0,300";
            
        $result = mysqli_query($this->connection, $transaction_query);
        
        return $result;
    }
        
    /*Function validates user account for user ID*/
    public function validate_useraccount(){
                        
        $account_query = "SELECT UserID FROM BankAccount WHERE UserID = " . $this->accountid;
        $results = mysqli_query($this->connection, $account_query);
        $db_array = mysqli_fetch_array($results);
        $return_value = 1;
                        
                if(count($db_array()) < 1)
                {
                    $return_value = 0;
                }  
                    return $return_value;
                    }
    
    /*Deposit*/
    public function deposit($UserID=0, $BankAccountID=0, $DepositAmount=0){
        $getbalance = mysqli_fetch_assoc($this->retrieve_current_balance());
        $currentbalance = $getbalance['CurrentBalance'];
        $today = date('Y-m-d', mktime());
        
        /*Deposit Funds*/
        $newbalance = $currentbalance + $DepositAmount;
        $deposit = mysqli_query($this->connection, "UPDATE BankAccount SET CurrentBalance = $newbalance WHERE BankAccountID = $BankAccountID");
        
        if($deposit){ //transaction completed
        
        /*Update Transaction log*/
        $log_query = "INSERT INTO TransactionLog(TransactionTypeID, BankAccountID, UserID, TransactionAmount, TransactionDate) VALUES (1, $BankAccountID, $UserID, $DepositAmount, '$today')";    
        
        mysqli_query($this->connection, $log_query);
        }
        
        /*New Balance*/
        return $newbalance;    
        
    }
} //End of class

?>

 
Helpful Member!  jpadie (TechnicalUser)
28 Apr 12 6:49
the bank account class appears to work if you get some data from it.

the while loop in your first post appears correctly constructed save that these two lines are incorrect

CODE

echo "\t" . '<td>' .  $account($transactionlog['TransactionType']) . '</td>' . "\n";
echo "\t" . '<td>$' . $account($transactionlog['TransactionAmount'], 2) . '</td>' . "\n";

replace them with the following

CODE

echo "\t" . '<td>' .  $transactionlog['TransactionType']) . '</td>' . "\n";
echo "\t" . '<td>' . number_format($transactionlog['TransactionAmount'], 2) . '</td>' . "\n";

the next line relates to a $balance object.  i do not know where you are creating that but i'd guess that $balance is supposed to be $transactionlog.

if this does not fix the problem then you will need to post the retrieve_all_accounts method and associated class (and check/doublecheck that there are in fact more than one account to that user id)

 
novice60 (TechnicalUser)
28 Apr 12 12:02
Thanks..  You pointed me in the right direction.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close