jowy jowy - 13 days ago 6
MySQL Question

I want to convert a normal mysql query to codeigniter

I want to convert a normal mysql select query to codeigniter

SELECT count(*)

leave_status
,
teacher_id
FROM
teacher_attendance
WHERE teacher_id='1' &
leave_status
='1' group by
teacher_id


this is what i have tried

$attendance = $this->db->get_where('teacher_attendance', array('year' => $running_year, 'timestamp' => $timestamp, 'teacher_id' => $row['teacher_id']))->result_array();


what i want to do is get the count of leave_status by teacher id

Answer
$this->db->select("count(*) as leave_status, teacher_id");
    $this->db->from("teacher_attendance");
    $this->db->where("teacher_id = 1 AND leave_status='1'");
    $this->db->group_by("teacher_id");
    $query = $this->db->get();       
    if ($query->num_rows() > 0) {
        $result = $query->result_array();
    }