2015-01-20 162 views
-1

我收到錯誤消息:在我的視圖中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; 
         ?>  

我已經從這個錯誤文件

+0

get_user_all看起來像什麼? (你沒有發佈你的模型,你發佈了兩次你的觀點。) – 2015-01-20 22:10:56

+0

對不起,先生,這種模式 – 2015-01-21 00:34:03

+0

功能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

回答

0

T他不是你正在使用的正確的編碼技術。因此,請首先糾正您的型號查詢代碼,例如:

$query = $this->db->from('petugas')->order_by('id_petugas','ASC')->get()->result(); 
return $query; 

無需更改其他任何東西。您將看到您的所有數據。

我希望這會幫助你。

0
function get_user_all() 
{ 
    $query=$this->db->query("select * from petugas order by asc"); 
    return $query->result(); 
    $this->db->select('*'); 
    $this->db->from('petugas'); 
    $this->db->order_by('id_petugas','ASC'); 
    $query=$this->db->get(); 
    if($query->num_rows() > 0){ 
    foreach($query->result() as $data){ 
     $daftar[]= $data; 
    } 
    return $daftar; 
    } 
} 
0

OK,它的工作..感謝了很多

我的登錄系統就可以了。它的工作..我有三個用戶類型1.admin 2.customer服務3.服務員。 我需要,如果登錄到管理員和CS或服務員。其重定向三種不同的看法...

我試過轉移兩個不同的意見,應該如何分配兩個以上的意見?

<?php if($level == "1"){ ?> 
    <?php echo $this->view('admin/template'); ?> 
<?php } else { ?> 
    <?php echo $this->view('cs/template'); ?> 
<?php } ?> 
相關問題