0
//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;?>
這是代碼。每次它說爲foreach提供的未定義變量和無效參數。請幫助一切正常,但它說嚴重性:通知消息:未定義的變量:類別
,查看哪裏是定義的變量$類別?我認爲你的意思是:$ categories = $ this-> registrant_model-> getAllDepartment(); –
我想你的意思是輸入'$ data ['categories']'而不是'$ categories' – Pete
[PHP:「Notice:Undefined variable」和「Notice:Undefined index」](http:// stackoverflow。 com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – ShiraNai7