title: Codeigniter: fetching records and sum
body: <p>I have the following table and I am trying to display the sum of <code>p_total</code> along with all other records in the table. I have managed to display the total amount but if I display it, only values of the fist row of the table shows up. Although the sum of p_total is showing correctly as 600 .</p>
  
  <p>Could you please tell me where is the problem in my code below:</p>
  
  <p>Thanks in advance :)</p>
  
  <p>My DB Table:</p>
  
  <pre><code> p_id   p_name    p_quantity    p_rate   p_total       user_id
    1     Pepsi        12           30       360            1
    2     Hot Breads   12           20       240            1
  </code></pre>
  
  <p>I have the following code in my model</p>
  
  <pre><code>$this-&gt;db-&gt;select('*,SUM(temporary_table.p_total AS Total');
  $this-&gt;db-&gt;from('temporary_table');
  $this-&gt;db-&gt;where('user_id',$user_id);                                   
  $getData = $this-&gt;db-&gt;get('');
  
  if($getData-&gt;num_rows() &gt; 0) {
     return $getData-&gt;result_array();
  }
  
  else { 
     return null;
  }
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>$this-&gt;load-&gt;model('mod_sales');
  $data['records']= $this-&gt;mod_sales-&gt;add_to_temporary_table($user_id);
  </code></pre>
  
  <p>My View:</p>
  
  <pre><code> foreach ($records as $row)
   {   
     &lt;td&gt;&lt;?php echo $row['p_name'];?&gt;&lt;/td&gt;
     &lt;td&gt;&lt;?php echo $row['p_quantity'];?&gt;&lt;/td&gt;
     &lt;td&gt;&lt;?php echo $row['p_rate'];?&gt;&lt;/td&gt;
     &lt;td&gt;&lt;?php echo $row['p_total'];?&gt;&lt;/td&gt;
   }
  
  &lt;?php echo $row['Total'];?&gt;
  </code></pre>