簡體   English   中英

如何從codeigniter中的mysql表中獲取所有行

[英]how to get all the rows from mysql table in codeigniter

我正在使用以下代碼

$this->db->select('moduleId,actionId');
        $this->db->from('role');
        $this->db->where('roleId',$session_data['role']);
        $role=$this->db->get();

        foreach ($role->result_array() as $rows)
        {
            $module=explode(":",$rows['moduleId']);
            $this->db->select('moduleId,moduleName,moduleUrl');
            $this->db->from('module');
            $this->db->where_in('moduleId',$module);
            $row=$this->db->get();
            $result=$row->row_array();
        }

但只有一行會來。如何獲取所有行,請幫助我

要在循環之外獲取數據,您應該將變量數組設為$result[] 因此,請按以下方式操作:

$this->db->select('moduleId,actionId');
            $this->db->from('role');
            $this->db->where('roleId',$session_data['role']);
            $role=$this->db->get();

            foreach ($role->result_array() as $rows)
            {
                $module=explode(":",$rows['moduleId']);
                $this->db->select('moduleId,moduleName,moduleUrl');
                $this->db->from('module');
                $this->db->where_in('moduleId',$module);
                $row=$this->db->get();
                $result[] = $row->row_array();
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM