How to Loop and Count Data From 2 Separate Tables in Codeigniter?
<p>thank you for your help on <a href="https://i.stack.imgur.com/xyEoQ.png" rel="nofollow noreferrer">my previous question</a> about Codeigniter </p>

<p><strong>UPDATE</strong> : Since everyone got a little confused by my question, I have edited my question.</p>

<p>I'm working in a banking company, and my project is creating a real-time monitoring for my company's clients transactions.</p>

<p>I need help in creating a HTML table that shows the total transaction of each of the Client both SUCCESS and FAILURE it. The HTML table should look like below:</p>

<p><a href="https://i.stack.imgur.com/xyEoQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xyEoQ.png" alt="Example Table"></a></p>

<p>Here's my database structure (I can't change the structure, coz I don't have the root access)</p>

<p><strong><em>Database A</em></strong> (Contained bank name and their ID code)</p>

<p><em>Table 1</em> = BankName, ATMNode, CardNode, BankGroup, CDC</p>

<p><strong><em>Database B</em></strong> (Contained all the transaction data like the date, the encryption and the encrypted card number)</p>

<p><em>Table 2</em> = Postid, Transid, SettleID, ATMNode, Rsp_Code, CDC</p>

<p>Now, I have successfully looped all of the bank name in my model. All I need to do is just COUNT the SUCCESS and FAILURE row from each of the bank name and then loop the count result.</p>

<p>At first I created 1 function for 1 bank name, but then I got a tip from someone that's not how it works. He said that I need to create a parameter or something with the looped bank name, and then I can loop the COUNT data for each of the bank name.</p>

<p>So here's my model:</p>

<pre><code>&lt;?php class Dash_model extends CI_Model {

        public function __construct()
        {
                // Cal CI Constructor
                parent::__construct();
                // Load Database A.
                $CI = &amp;get_instance();
                //setting the second parameter to TRUE (Boolean) the function will return the database object.
                $this-&gt;db2 = $CI-&gt;load-&gt;database('db2', TRUE);
        }

        // Get all the bank name
        public function getbanklist()
        {
            $query = $this-&gt;db2-&gt;query("SELECT BankName FROM Table1 ORDER BY BankName");
            return ($query-&gt;result());

        }

        function transapproved() // Counting Success
        {
            // Database B autoloaded in autoload.php
            $this-&gt;db-&gt;select('TransID');
            $this-&gt;db-&gt;from('Table2');
            $this-&gt;db-&gt;join('Table1', 'Table1.CDC = Table2.CDC', 'inner');
            $this-&gt;db-&gt;where('BankName', $getbanklist);
            $this-&gt;db-&gt;where('Rsp_code', '01');
            $data = $this-&gt;db-&gt;get();
            return $this-&gt;data-&gt;num_rows();

        }

        function transfailure() // Counting Failure
        {
            // Database B autoloaded in autoload.php
            $this-&gt;db-&gt;select('TransID');
            $this-&gt;db-&gt;from('Table2');
            $this-&gt;db-&gt;join('Table1', 'Table1.CDC = Table2.CDC', 'inner');
            $this-&gt;db-&gt;where('BankName', $getbanklist);
            $this-&gt;db-&gt;where('Rsp_code', '02');
            data = $this-&gt;db-&gt;get();
            return $this-&gt;data-&gt;num_rows();
        }

}

?&gt;
</code></pre>

<p>Of course my model is not working. It didn't return anything. Even if it work, it only return one row. So I need your help guys.</p>

<p>And then here's my controller: </p>

<pre><code>&lt;?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Dash_control extends CI_Controller {

    public function __construct()
       {
            parent::__construct();
            $this-&gt;load-&gt;model('dash_model');
            $this-&gt;load-&gt;library('table');
       }

    public function index()
    {
        $tmpl = array (
        'row_start'           =&gt; '&lt;tr&gt;',
        'row_end'             =&gt; '&lt;/tr&gt;',
        'cell_start'          =&gt; '&lt;td&gt;',
        'cell_end'            =&gt; '&lt;/td&gt;',
        );

        $this-&gt;table-&gt;set_template($tmpl); 

        $data['banknamehere'] = $this-&gt;dash_model-&gt;getbanklist();

        $this-&gt;load-&gt;view('dashboard',$data);
    }


}
</code></pre>

<p>And then I passed it to my VIEW:</p>

<pre><code>&lt;table class="table table-bordered table-hover"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Bank Name&lt;/th&gt;
&lt;th&gt;Trans Success&lt;/th&gt;
&lt;th&gt;Trans Failure&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;?php foreach ($banknamehere as $row)
{ ?&gt;
&lt;tr&gt;&lt;td&gt;&lt;?php echo $row-&gt;banknamehere; ?&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;?php } ?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</code></pre>

<p>Yes, everything didn't work. I think the key must be in the model. But I don't know how.
Thank you for your help...</p>