我收到錯誤消息:在我的視圖中foreach()的無效參數。我想顯示我的MySQL表中的所有條目,但我一直在收到錯誤消息。我是Codeigniter的新手,無法真正弄清楚如何解決這個問題。該代碼如下......請幫助我爲foreach()提供的參數無效codeigniter
user_model.php
<?php
foreach ($daftar as $data) :
?>
<tr>
<td><?php echo $data->id_petugas; ?></td>
<td></td>
<td></td>
<td></td>
<td>
<button class="btn edit"><i class="icon-edit"></i></button>
<button class="btn btn-danger remove" data-toggle="confirmation">
<i class="icon-remove"></i></button>
</td>
</tr>
<?php
endforeach;
?>
user_controller
<?php
class User_controller extends CI_Controller{
function __Construct()
{
parent ::__construct();
}
function user(){
$this->load->model('user_model');
$data['daftar'] = $this->user_model->get_user_all();
$this->load->view('daftar_user',$data);
}
daftar_user.php
<?php
foreach ($daftar as $data) :
?>
<tr>
<td><?php echo $data->id_petugas; ?></td>
<td></td>
<td></td>
<td></td>
<td>
<button class="btn edit"><i class="icon-edit"></i></button>
<button class="btn btn-danger remove" data-toggle="confirmation">
<i class="icon-remove"></i></button>
</td>
</tr>
<?php
endforeach;
?>
我已經從這個錯誤文件
get_user_all看起來像什麼? (你沒有發佈你的模型,你發佈了兩次你的觀點。) – 2015-01-20 22:10:56
對不起,先生,這種模式 – 2015-01-21 00:34:03
功能get_user_all() \t \t { \t \t \t $查詢= $這個 - > DB->查詢( 「SELECT * FROM petugas爲了通過ASC」); \t \t \t return $ query-> result(); \t \t \t \t \t $ this-> db-> select('*'); \t \t \t $ this-> db-> from('petugas'); \t \t \t $ this-> db-> order_by('id_petugas','ASC'); \t \t \t \t \t \t $ query = $ this-> db-> get(); \t \t \t \t如果($查詢 - > NUM_ROWS()> 0){ \t \t \t \t \t的foreach($查詢 - >結果()作爲$數據){ \t \t \t \t \t \t $ daftar [] = $數據; \t \t \t \t \t} \t \t \t \t回$ daftar; \t \t \t \t} \t \t \t \t \t} – 2015-01-21 00:34:47