Php 列出CodeIgniter中表的一些用户
您好,我想从数据库中的表中列出一些用户 型号:Php 列出CodeIgniter中表的一些用户,php,mysql,codeigniter,model-view-controller,Php,Mysql,Codeigniter,Model View Controller,您好,我想从数据库中的表中列出一些用户 型号: class listPatients { private $list_patients; function __construct() { $this->list_patients = array($patient); } //put your code here function list_patients() { $this->db->from('U
class listPatients {
private $list_patients;
function __construct() {
$this->list_patients = array($patient);
}
//put your code here
function list_patients() {
$this->db->from('Users');
$this->db->where('patient', 1);
$this->db->select('id, username, Email');
$patient[]=$this->db->get()->result();
return $patient[];
}
`
看法
我想显示一个患者列表(列patient=1的用户),我遇到了一些问题。从Db检索数据后,是否有人可以帮助我?不要传递整个结果对象。而不是传递整个$patient(结果对象)。将结果_对象存储到变量并传递它,即$patient=$patient[0];在模型中更改此行
function list_patients() {
$this->db->from('Users');
$this->db->where('patient', 1);
$this->db->select('id, username, Email');
$patient=$this->db->get()->result();//change
$patient = $patient[0];//
return $patient;//
}
//controller
public function list_patients() {
$data["list_patients"] = $this->listPatients->list_patients();
$this->load->view('mainview',$data);
}
//view in mainview.php
foreach ($list_patients as $value) {
echo $value->patient;
}
您遇到了什么问题?我发现了这个错误:遇到了PHP错误严重性:注意消息:未定义变量:患者文件名:views/mainview.PHP行号:58 Backtrace:File:/home/a15_web01/web/app/application/views/mainview.PHP行:58函数:_error\u handler文件:/home/a15_web01/web/app/application/controllers/Main.php行:18函数:解析文件:/home/a15_web01/web/app/index.php行:292函数:require\n您试过我的答案了吗
public function list_patients() {
$data["list_patients"] = $this->listPatients->list_patients();
$this->load->view('mainview',$data);
}
function list_patients() {
$this->db->from('Users');
$this->db->where('patient', 1);
$this->db->select('id, username, Email');
$patient=$this->db->get()->result();//change
$patient = $patient[0];//
return $patient;//
}
//controller
public function list_patients() {
$data["list_patients"] = $this->listPatients->list_patients();
$this->load->view('mainview',$data);
}
//view in mainview.php
foreach ($list_patients as $value) {
echo $value->patient;
}