count() rows in database using codeigniter
<p>This is the model (Excel.php) :</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>function undangan($req_id)
    {
        
        $this-&gt;db-&gt;select("excel_id,request_id,to_name as nama,to_address as alamat_tujuan,to_zipcode as kode_pos, ifnull(tariff,0) as tarif ");
        $this-&gt;db-&gt;where('tariff = 0 and request_id =', $req_id);
        $query  =   $this-&gt;db-&gt;get('excel');
        return $query-&gt;result_array();
    }</code></pre>
</div>
</div>
</p>

<p>This is the controller (Admin.php) :</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>function undangan()
    { 
     $this-&gt;load-&gt;model('excel');
        $this-&gt;load-&gt;model('request'); 
     $data['results']   =   $this-&gt;request-&gt;request();       
        foreach ( $data['results'] as $key)
        {
            $tarif=0;
            $req_id = $key['req'];
            $data['tarif'][$req_id] =   $this-&gt;excel-&gt;total_tarif($req_id); 
            $data['undg'][$req_id]   =   $this-&gt;excel-&gt;undangan($req_id);
            foreach ($data['undg'][$req_id] as $value)
            {

                $tarif += $value['tarif']; 
                $this-&gt;db-&gt;where('request_id', $value['request_id']);
                $num_rows = $this-&gt;db-&gt;count_all_results('excel');
                var_dump($num_rows);
            }
           
            $tarif = $data['tarif'][$req_id];
        }
           
        $this-&gt;load-&gt;view('admin_view',$data);
          
    } </code></pre>
</div>
</div>
</p>

<p>And the view (admin_view.php) :</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
&lt;h3&gt;Customer Request&lt;/h3&gt;

&lt;?php
    foreach ($results as $value) {
  
    ?&gt;
    &lt;div class="panel panel-primary"&gt;
        &lt;table class="table" align="center"&gt;
       
            &lt;tr class="primary" align="center"&gt;

                &lt;td&gt;&lt;?php echo $value['nama']?&gt;&lt;/td&gt;

                &lt;td&gt;&lt;?php echo $value['email']?&gt;&lt;/td&gt;

                &lt;td&gt;&lt;?php echo $value['phone']; ?&gt;&lt;/td&gt;

                &lt;td&gt;&lt;?php echo $value['alamat_pengirim']?&gt;&lt;/td&gt;  
                
                &lt;td id="total_&lt;?php echo $value['req']?&gt;"&gt;
                &lt;span &gt; &lt;?php echo $tarif[$value['req']][0]['tarif']?&gt;
                &lt;/td&gt;

                &lt;td&gt;
                &lt;button id="kirim_email" type="button" class="btn btn-success" onclick=update_status(&lt;?php echo $value['req']?&gt;) &gt;
                 &lt;span class="glyphicon glyphicon-envelope" aria-hidden="true" &gt;&lt;/span&gt; Kirim Email
                &lt;/button&gt;
                &lt;/td&gt;

                &lt;td&gt;
                &lt;button  type="button" class="btn btn-success" onclick=tariff(&lt;?php echo $value['req']?&gt;)&gt;
                &lt;span class="glyphicon glyphicon-thumbs-up" aria-hidden="true" &gt;&lt;/span&gt; Auto Tarif
                &lt;/button&gt;
                &lt;/td&gt;

            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/div&gt;  


    &lt;table class="table table-striped table-bordered" align="center" width="400px" &gt;
        &lt;tr align="center" class="success"&gt;
            &lt;th&gt;
                Alamat
            &lt;/th&gt;
            &lt;th&gt;
                Zip Code
            &lt;/th&gt;
            
            &lt;th&gt;
                Tarif
            &lt;/th&gt;
            
            &lt;th&gt;
                Action
            &lt;/th&gt;
        &lt;/tr&gt;
  
        &lt;?php        
         foreach ($undg[$value['req']] as $row) {        
        ?&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;?php echo $row['alamat_tujuan']?&gt;
            &lt;/td&gt;

            &lt;td&gt;
            &lt;input type="text" class="form-control col-md-2"  id="zip_&lt;?php echo $row['excel_id']?&gt;"  value="&lt;?php echo $row['kode_pos']?&gt;"&gt;
            &lt;/td&gt;

            &lt;td&gt;
            &lt;input type="text" class="form-control col-md-2"  id="&lt;?php echo $row['excel_id']?&gt;"  name="tariff" value="&lt;?php echo $row['tarif']?&gt;"&gt;
            &lt;/td&gt;

            &lt;td&gt;
            &lt;button  type="button" id="ref_butn" class="btn btn-md" onclick="update(&lt;?php echo $row['excel_id']?&gt; )"&gt;
            &lt;span class="glyphicon glyphicon-floppy-save" aria-hidden="true" &gt;&lt;/span&gt; Save
            &lt;/button&gt;
            &lt;/td&gt;

        &lt;/tr&gt;
    &lt;?php    } ?&gt;
    &lt;/table&gt;
    &lt;?php }; ?&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>I want to count rows from table excel where 'request_id' = something..
I did the count_all_result inside foreach in controller, but it gives me :</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>int(3) int(3) int(3) int(3) int(3) int(3) int(2) int(2) int(3) int(3) int(3) int(2) int(2)</code></pre>
</div>
</div>
</p>

<p>This is not the actual total of rows. Where i should count_all_result? Help me to solve this.. Thank you</p>