在下面的代码中我看到了错误,如何解决?
表格中的数据如下:
是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;
}
错误:
遇到PHP错误
严重性:警告
消息:为foreach()提供的参数无效
文件名:core / Loader.php(679):eval()'d code
行号:279
答案 0 :(得分: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);
}
答案 1 :(得分:0)
也许你应该尝试:
for($i=0;$i<count($query_hi);$i++)
{
echo $query_hi[$i]->images;
}