我对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>";
}
?>
最佳答案
在return $query->result();
函数中使用return $query->result;
而不是you()
。result
是一个方法,而不是类成员。
关于php - 未定义的属性:CI_DB_mysql_result::$ result,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17234924/