我无法解决以下错误
遇到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;
?>
答案 0 :(得分:1)
您在Controller
$data['results'] = $this->get_company_model->get_all();
^It should be:
$data['results'] = $this->get_company_model->get_All();
注意资本A
OR
尝试回显模型中的查询以检查您的Query是否返回任何行。
$query = $this->db->query("SELECT name,id from companydetails");
echo $this->db->last_query();
return $query->result();