【发布时间】:2014-08-22 19:13:03
【问题描述】:
我无法修复以下错误
遇到了 PHP 错误
严重性:通知
消息:未定义变量:结果
文件名:views/view_nav.php
行号:22
遇到了 PHP 错误
严重性:警告
消息:为 foreach() 提供的参数无效
文件名:views/view_nav.php
行号:22
这是我的代码
控制器
public function home(){
$this->load->model('get_company_model');
$this->load->view('view_header');
$data['results'] = $this->get_company_model->get_all();
$this->load->view('view_nav',$data);
$this->load->view('view_content');
$this->load->view('view_footer');
}
型号
public function get_All(){
$query = $this->db->query("SELECT name,id from companydetails");
return $query->result();
}
public function get_branch($companyID){
$query = $this->db->query("SELECT name,id from branches WHERE companyid='".$companyID."'");
return $query->result();
}
查看
<?php
foreach($results as $row):
?>
<div>
<ol class="tree">
<li>
<label for="folder1"><a href="<?php echo site_url('site2/about'); ?>"><?=$row->name?></label></a> <input type="checkbox" id="folder1" />
<ol>
<?php
$myresult=$this->get_company_model->get_branch($row->id);
foreach($myresult as $row2):
?>
<li class="file"><a href="#"><?=$row2->name?></a></li>
<?php
endforeach;
?>
【问题讨论】:
标签: php codeigniter