Postingan lainnya
Menghitung row dalam database?
mohon arahannya agan agan semua.. apakah ada cara lain untuk count jumlah laki-laki dan perempuan kayak count array?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Karyawan extends CI_Model {
public function getAll() {
return $this->db->get('karyawan')->result();
}
public function count() {
return $this->db->count_all('karyawan');
}
public function countMen() {
$this->db->where('gender', 'laki-laki');
$this->db->from('karyawan');
return $this->db->count_all_results();
}
public function countWoman() {
$this->db->where('gender', 'perempuan');
$this->db->from('karyawan');
return $this->db->count_all_results();
}
}
0
1 Jawaban:
bisa menggunakan num_rows()
public function countMen() { $this->db->where('gender', 'laki-laki'); $this->db->from('karyawan'); return $this->db->get(); }
$data=$this->karyawan->countMen(); $count=$data->num_rows();
0