A PHP error was encountered
Severity:Notice
Message:Undefined variable:pub
Filename:views/first.php
Line number:25
这是我的代码:
Cotroller
$data['pub']=$this->mymodel->get_public();
$this->load->view('first',$data);
模型
function pub_article()
{
$where=array('public'=>'1');
$query=$this->db->get_where('article',$where);
if($query->num_rows() > 0)
return $query->result();
else
return false;
}
视图的
foreach($pub->result() as $row){
echo "<p>".$row->tiltl."</p>"
}
答案 0 :(得分:1)
试试这段代码:
模特:
$where=array('public'=>'1');
$query=$this->db->get_where('article',$where);
if($query->num_rows() > 0)
return $query;
else
return false;
在您看来:
if($pub!=false)
{
foreach($pub->result() as $row){
echo "<p>".$row->tiltl."</p>"
}
}