Hello,
I have a table for personal data, which contains contents such as name, address, gender, etc.
now I want to calculate the total male or female from the gender column, so I make a sql query like this:
the result is :
So, how do I write the code on the model and controller and display it on my website?
this is my code so far:
Thank you and sorry for my bad english
I have a table for personal data, which contains contents such as name, address, gender, etc.
now I want to calculate the total male or female from the gender column, so I make a sql query like this:
Code:
SELECT gender, COUNT(*) AS total
FROM personaldata
GROUP BY genderthe result is :
Quote:man : 3
woman : 6
So, how do I write the code on the model and controller and display it on my website?
this is my code so far:
PHP Code:
public function total_gender()
{
$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();
}
Thank you and sorry for my bad english
![[Image: screen.png]](http://i.ibb.co/2tfTh17/screen.png)
, need an automated way for an idea I just had.