I'm trying to fetch data from my database to a data table with table headers "Total No. of Students | Male | Female"
This is the error it showed
Severity: Notice
Message: Undefined property: stdClass::$totalcount
Filename: pages/studentgender.php
Line Number: 20
Backtrace:
File: C:\xampp\htdocs\libsystem\application\views\pages\studentgender.php Line: 20 Function: _error_handler
File: C:\xampp\htdocs\libsystem\application\controllers\Students.php Line: 30 Function: view
This is my model
public function studentCountGender(){
    $this->db->select('studgender, COUNT(*) as totalcount, COUNT(   case when studgender = "Male" then 1 else 0 end)
                        AS malecount, COUNT(    case when studgender = "Female" then 1 else 0 end) AS femalecount');
    $this->db->from('student');
    $query = $this->db->get();
    return $query->result();
}
}
This is my controller
 public function studentList(){
    $this->load->model('student_model');
    $data['result'] = $this->student_model->studentCountGender();
    $this->load->view('templates/header');
    $this->load->view('templates/sidebar');
    $this->load->view('pages/studentgender', $data);
}
This is my view
    <thead>
        <tr>
          <th>Total No. of Students</th>
            <th>Total Number of Males</th>
            <th>Total Number of Females</th>
        </tr>
    </thead>
    <tbody> 
    <?php
    foreach($sample as $item){
      echo '<tr>
        <td>'.$item->totalcount.'</td>
        <td>'.$item->malecount.'</td>
        <td>'.$item->femalecount.'</td>
      </tr>
    </tbody>
    ';}?>
</table>
            </div>
        </div>
    </div>
</div>
Can someone help me how to parse it and it will not show the error? I've been trying to debug this for 2 hours and it's making me insane thanks alot!!!
 
     
     
     
     
     
     
    