开发者

Invalid argument supplied

开发者 https://www.devze.com 2023-04-11 11:07 出处:网络
In following code i has error in view, how can fix it? My data in table is as: CI_Controller: $update = array(\'15\'); // this is a example from my $_POST that are array.

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

精彩评论

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