• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Catatan Codeigniter Get Sum Value From MySql Query

Kepala Suku

Web & Mobile Developer
Staff member
#1
Below Function is used for getting sum value from MySql query:
PHP:
function getRemainder($id){
  $q = $this->db->select("SUM(QTYMuat) as total_qty from distribusi WHERE NoTransaksi1 ='$id' OR NoTransaksi2 = '$id'");
  $response = $q->get()->row();
  return $response->total_qty;
 }
I put that function inside a model named Api_model. Then i could use that function from a controller or view using this line: $this->Api_model->getRemainder("ID_RECORD")