$this->db->order_by("layer字段", "asc");
$this->db->order_by("orders字段", "asc");
$data = $this->db->get('表');
foreach($data->result_array() as $row) {
if($row['group_parent_id'] == $gid) {
$result[$row['gid']] = $row;
$index[$row['gid']] =& $result[$row['gid']];
}else {
$index[$row['group_parent_id']][$row['gid']] = $row;
$index[$row['gid']] =& $index[$row['group_parent_id']][$row['gid']];
}
}
return $result;