【问题标题】:Invalid argument supplied提供的参数无效
【发布时间】:2011-10-06 16:46:43
【问题描述】:

在下面的代码中我看到错误,如何解决?

我在表中的数据如下:

CI_控制器:

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

错误:

遇到 PHP 错误

严重性:警告

消息:为 foreach() 提供的参数无效

文件名:core/Loader.php(679) : eval()'d code

行号:279

【问题讨论】:

  • 在加载视图并将输出添加到您的问题之前执行var_dump($data['query_hi']);

标签: php codeigniter foreach


【解决方案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);
}

【讨论】:

    【解决方案2】:

    也许你应该试试:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 2011-02-07
      相关资源
      最近更新 更多