开发者

Invalid argument supplied

In following code i has error in view, how can fix it?

My data in table is as:

Invalid argument supplied

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);
    }

View:

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

Error:

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

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

Line Number: 279


The problem is that it returns only one result for your query... and the array is overridden at each cycle. Try this:

$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);
}


Maybe you should try:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜