【问题标题】:List some users of a Table in CodeIgniter列出 CodeIgniter 中某个表的一些用户
【发布时间】:2015-11-12 17:23:37
【问题描述】:

您好,我想从我的数据库中的表中列出一些用户。

型号:

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),我遇到了一些问题,有人可以帮忙

【问题讨论】:

  • 你遇到了什么问题?
  • 我收到此错误:遇到 PHP 错误 严重性:通知消息:未定义变量:患者文件名:views/mainview.php 行号:58 回溯:文件: /home/a15_web01/web/app/application/views/mainview.php 行:58 功能:_error_handler 文件:/home/a15_web01/web/app/application/controllers/Main.php 行:18 功能:解析文件:/home /a15_web01/web/app/index.php 行:292 功能:require_once
  • 你试过我的答案了吗

标签: php mysql codeigniter model-view-controller


【解决方案1】:

从 Db 检索数据后,不要传递整个 result_object。而不是传递整个 $patient(result 对象)。将 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    相关资源
    最近更新 更多