Towhid
Towhid

Reputation: 1

How can i get rank or position base highest ' gpa' and 'total' into database rows data in codeigniter?

How can i get rank or position base highest ' gpa' and 'total' into database rows data in codeigniter?

public function fetchData() {
    $data = array();
    $data['fetch_data'] = $this->excel_data_insert_model->fetch_data();
    $result = $data['fetch_data']->result();
    foreach ($result as $row) {
        //echo $row.'<br/>';
        $id = $row->id;
        $p_student_id = $row->stu_id;
        $p_section = $row->section;
        $p_gpa = $row->gpa;
        $p_total = $row->total;
        $x = 0;
    }
} 

Upvotes: 0

Views: 90

Answers (1)

Jaymin
Jaymin

Reputation: 1661

My Answer to your raw query could be this:

Select column_name1, column_name2, MAX(gpa),MAX(total) from tbl_v1 ORDER by gpa, total desc

Also for CI

$query=$this->db->select('column_name1, column_name2, MAX(gpa),MAX(total)')->order_by('gpa,total','desc'‌​)->get('tbl_v1'); 
return $query;

Upvotes: 1

Related Questions