1
//controller:
private function getAll() {

    $data['categories'] = $this->registrant_model->getAllDepartment();
    $this->load->view('SystemAdminUser/registrant', $data);

}

//model:
public function getAllDepartment() {
    $this->db->select('*')->from('patient_db');
    $query = $this->db->get();
    return $query->result_array();

}


//view:
<?php foreach($categories as $c):?>
    <tr>
        <td><?php echo $c['id'];?></td>
        <td><?php echo $c['phone'];?></td>
        <td><?php echo $c['name'];?></td>
    </tr>
<?php endforeach;?>

this is the code. every time it says undefined variable and Invalid argument supplied for foreach. please help

oxy
  • 454
  • 4
  • 8

1 Answers1

2

You need to pass $data array to view from controller

$data['categories'] = $this->registrant_model->getAllDepartment();
$this->load->view('SystemAdminUser/registrant', $data);// pass $data to view
Saty
  • 22,443
  • 7
  • 33
  • 51