您好,我想列出数据库表中的一些用户。
型号:
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[];
}
`
查看
<?php echo $patient[] ?>
控制:
public function list_patients() {
$data["list_patients"] = $this->listPatients->list_patients();
$this->load->view('mainview',$data);
}
我想显示患者列表(列患者 = 1 的用户),我遇到了一些问题,有人可以帮忙吗
最佳答案
从 Db 检索数据后,不要传递整个 result_object。而不是传递整个 $ Patient(结果对象)。将 result_object 存储到变量并传递它,即 $ 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 - 在 CodeIgniter 中列出表的一些用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33677497/