简体   繁体   中英

how to get all the rows from mysql table in codeigniter

I am using the following code

$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();
        }

but only one row will come.how to get all the rows,please help me

To get data outside of loop you should make the variable array as $result[] . So, do as the below way :

$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();
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM