2015-09-26 56 views
-2
  1. 型號未定義的變量:結果

    public function show() 
    { 
        $query = $this->db->get('text'); 
        return $query->result(); 
    } 
    

2.Controller

public function inf() 
    { 
     $this->load->model('addm'); 
     $data['results'] = $this->addm->show($query); 

     $this->load->view('backend/first',$data); 

    } 

3.view

我想從我的分貝,但我得到的數據無法解決此錯誤: 未定義的變量:結果

<?php 
echo"<td>"; 

if (is_array($result)) { 
    foreach ($result() as $row) { 
     $id = $row->id; 
     $words = $row->words; 
     } 
} 

echo "</td>"; 
?> 

回答

1

幾樣東西,

  • 在你的模型功能顯示不期待任何參數
  • $this->addm->show();因爲不需要
  • 在視圖變量應該是刪除$query結果不是結果

    // controller 
    public function inf() 
    
    { 
        $this->load->model('addm'); 
        $data['results'] = $this->addm->show(); 
        $this->load->view('backend/first', $data); 
    } 
    
    
    // view 
    if (!empty($results)) { 
        foreach($results as $row) { 
         $id = $row->id; 
         $words = $row->words; 
        } 
    } 
    
    // model 
    public function show() 
    
    { 
        $query = $this->db->get('text'); 
        return $query->result(); 
    } 
    
+0

模型公共職能秀() \t { \t \t \t \t $查詢= $這個 - > DB-> GET( '文'); \t \t return $ query-> result(); \t \t}控制器公共函數INF() \t \t { \t \t \t $這 - >負載>模型( 'ADDM'); \t \t \t $ data ['results'] = $ this-> addm-> show(); \t \t \t \t \t \t $這 - >負載>視圖( '後端/第一',$數據); \t \t} model <?php echo「​​」; ($ results)){ foreach($ results as $ row){ $ id = $ row-> id; $ words = $ row-> words; } } echo「」; ? > //我仍然有這個錯誤 – zeko50

+0

@ zeko50請告訴我你的錯誤檢查getting..and上面的代碼 – jlocker

+0

一個PHP錯誤遇到 嚴重性:注意 消息:未定義的變量:結果 文件名:後端/ first.php 行號:74 – zeko50