2011-10-06 194 views
0

在下面的代碼中,我有錯誤,如何解決?提供的參數無效

我在表中的數據是:

enter image description here

是CI_Controller:

$update = array('15'); // this is a example from my $_POST that are array. 
    if (is_array($update) && count($update) > 0) { 
     foreach($update as $val){ 
      $data['query_hi'] = $this->db->get_where('hotel_image', array('relation' => $val))->row(); 
     } 
     $this -> load -> view('admin/residence_update', $data); 
    } 

查看:

     foreach($query_hi->images as $val){ 
          echo $val; 
         } 

錯誤:

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: core/Loader.php(679) : eval()'d code

Line Number: 279

+0

在加載視圖並將輸出添加到您的問題之前,執行'var_dump($ data ['query_hi']);''。 – hakre

回答

1

的問題是,它僅返回一個結果爲您查詢......和陣列在每個循環覆蓋。試試這個:

$update = array('15'); // this is a example from my $_POST that are array. 
if (is_array($update) && count($update) > 0) { 
    $data= array(); 
    foreach($update as $val){ 
     $tmp= $this->db->get_where('hotel_image', array('relation' => $val)); 
     foreach($tmp->result() as $row){ 
      $data['query_hi'][] = $row; 
     } 
    } 
    $this -> load -> view('admin/residence_update', $data); 
} 
0

也許你應該嘗試:

for($i=0;$i<count($query_hi);$i++) 
{ 
    echo $query_hi[$i]->images; 
}