我是codeigniter编程的新手。当我尝试连接数据库并从表中检索数据时,我发现如下错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_DB_mysql_result::$result
Filename: models/haii.php
Line Number: 15.
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/getquery.php
Line Number: 2
我正在使用此代码使用 codeigniter 与数据库连接:
控制器:
<?php
class product extends CI_Controller
{
function __construct()
{
}
function getall()
{
$this->load->model('haii');
$data['query']=$this->haii->you();
$this->load->view('getquery',$data);
}
}
?>
模型:
<?php
class haii extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function you()
{
$query=$this->db->get('member');
return $query->result;
}
}
?>
看法:
<?php
foreach($query as $row)
{
print $row->username;
print $row->password;
print $row->fname;
print $row->lname;
print $row->contact;
print "<br>";
}
?>