title: Get maximum value of row in mysql ,using codeigniter
body: <p>Get maximum value of row in mysql using codeigniter.<br>
  i have following mysql data <a href="https://i.stack.imgur.com/32uRr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/32uRr.png" alt="enter image description here"></a></p>
  
  <p>I need to get the details based on <code>total_payment</code> of each student.
  like this<a href="https://i.stack.imgur.com/YBxKN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBxKN.png" alt="enter image description here"></a>
  <br></p>
  
  <p>i tried code below</p>
  
  <pre><code> $student_id_dis = $this-&gt;db-&gt;query('SELECT DISTINCT(student_id) FROM student_fees')-&gt;result_array();
   $fee_cat_id_dis = $this-&gt;db-&gt;query('SELECT DISTINCT(fee_category_id) FROM student_fees')-&gt;result_array();
   $this-&gt;db-&gt;select(['student_fees.*', 'fee_categories.fee_category_name as fee_name', 'fee_categories.amount as fee_amount']);
  
   $this-&gt;db-&gt;join('student', 'student_fees.student_id = student.student_id');
   $this-&gt;db-&gt;join('fee_categories', 'student_fees.fee_category_id = fee_categories.fee_categories_id');
  
   $where = '';
  
   for ($i = 0; $i &lt; count($student_id_dis); $i++) {
      if (isset($fee_cat_id_dis[$i]['fee_category_id'])) {
          $where .='total_paid = (SELECT max(stdp.total_paid)
                                     FROM student_fees stdp
                                     WHERE stdp.fee_category_id = ' . $fee_cat_id_dis[$i]['fee_category_id'] . ')';
       }
  
       $this-&gt;db-&gt;where($where);
  
       $this-&gt;db-&gt;get('student_fees')-&gt;result_array();
        }
  </code></pre>