I have a table that contains personal data, such as name, gender, address, etc. my question is, how to get the total number of men and women from my table?
This is my SQL query :
SELECT gender, COUNT(*) AS total
FROM personaldata
GROUP BY gender
This is my code so far in my model :
public function gender_count()
{
$this->db->select('gender, count(*) as total');
$this->db->from('personaldata');
$this->db->group_by('gender');
$query = $this->db->get()->row()->total;
return $query->result();
}
So how to write that SQL query to CI model and controller? I just want to show the total gender in my site.
Thank you
Model:
OR
Controller:
View: