title: How to count total number of rows in a view which retrieved from database
body: <p>I want to display some column in a table. Also, want to count the total number of rows showing in the table. I tried some ways, can you please help me if this is the right way or there are other better ways to do this.</p>
  
  <p>my Model</p>
  
  <pre><code>public function getRentedEquipments($project_id=0){
  
       return $this-&gt;db-&gt;select('e.*, p.project_id')
                 -&gt;from('equipment AS e')
                 -&gt;join('project AS p', 'p.project_id = e.project_id')
                 -&gt;where('p.project_id', $project_id)
                 -&gt;order_by('eq_name','ASC' )
                 -&gt;get()-&gt;result_array();
  }
  </code></pre>
  
  <p>My view</p>
  
  <pre><code>&lt;tbody&gt;
  
  &lt;?php 
  
  $total_eq=0;
    $count=1;
    foreach ($pr_eq as $row) {
  ?&gt;
  
   &lt;tr&gt;
        &lt;th scope="row"&gt;&lt;?php echo $count;?&gt;&lt;/th&gt;
        &lt;th scope="row"&gt;&lt;?php echo $row['eq_id'];?&gt; &lt;/th&gt;
        &lt;th scope="row"&gt;&lt;?php echo $row['eq_name'];?&gt; &lt;/th&gt;
  
    &lt;?php
   $total_eq+=$row['eq_id']-1;
    $count=$count+1;
    }
  
  ?&gt;
  &lt;button class="btn btn-info"&gt; Number of Equipments: &lt;?php echo $total_eq;?&gt;&lt;/button&gt; 
    &lt;/tbody&gt;
  </code></pre>
  
  <p>The output is showing correctly, but I just want to know if there are any better ways to do this.
  <a href="https://i.stack.imgur.com/3QDiL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3QDiL.png" alt="My output"></a></p>