从数据库中获取的记录得到错误这是我的代码
同时使用codeiginter
user_controller.php
public function get_users(){
//load the database
$this->load->database();
//load the model
$this->load->model('user_model');
//load the method of model
$this->user_model->select();
return //the data in view
$this->load->view('user_view', $data);
}
user_model.php
function select(){
$query = $this->db->select('barcodeout','barcodein','emp_id','emp_name','amount','time');
$this->db->from('porters');
$query = $this->db->get();
return $query->result();
}
user_view.php
<table>
<tr>
<td><strong>Ticket Out</strong></td>
<td><strong>Ticket In</strong></td>
<td><strong>Emp ID</strong></td>
<td><strong>Emp Name</strong></td>
<td><strong>Amount</strong></td>
<td><strong>Time</strong></td></tr>
<?php foreach($query->result() as $employee){ ?>
<tr>
<td><?=$employee->barcodeout;?></td>
<td><?=$employee->barcodein;?></td>
<td><?=$employee->emp_id;?></td>
<td><?=$employee->emp_name;?></td>
<td><?=$employee->amount;?></td>
<td><?=$employee->time;?></td>
</tr>
<?php }?>
</table>
</div>
</div>
我已经用这个试了很多东西,我得到的最后是'未定义的变量',建议我用三个MVC代码来获取数据库记录,它会真的很感激,谢谢。
发布你正在得到的确切错误 –
作为一个方面说明,在你的控制器中,你不需要在$ this-> load-> view之前使用“return”。只需加载视图和$数据。您还应该为模型返回使用条件语句。如果($ this-> user_model-> select()){$ data ['employees'] = $ query-> result()} – Brad