[英]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[]
.要在循环之外获取数据,您应该将变量数组设为$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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.