繁体   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