1

这是我的查询:

$this->db->select('e.emp_no', 'e.birth_date', 'e.first_name', 'e.last_name', 'e.gender', 'e.hire_date')
            ->from('employees AS e')
            ->join('titles AS t', 'e.emp_no = t.emp_no')
            ->join('salaries AS s', 't.emp_no = s.emp_no')
            ->join('dept_emp AS de', 's.emp_no = de.emp_no')
            ->join('departments AS d', 'de.dept_no = d.dept_no')
            ->join('dept_manager AS dm', 'd.dept_no = dm.dept_no')
            ->limit($limit, $offset)
            ->order_by($sort_by, $sort_order)
            ->group_by('e.emp_no')
            ->where('t.title', 'staff'); 

然后我用这个返回数组:

$ret['rows'] = $q->get()->result();

        print_r ($ret['rows']);

输出的只是emp_no:

Array ( [0] => stdClass Object ( [emp_no] => 10002 ) [1] => stdClass Object ( [emp_no] => 10005 ) [2] => stdClass Object ( [emp_no] => 10007 ) [3] => stdClass Object ( [emp_no] => 10011 ) )

如何输出所有选定的列?

PS:我也试过用result_array()什么都没用。

4

1 回答 1

0

您应该将所有字段名称组合成一个字符串,而不是将它们分隔为多个参数以select()发挥作用

$this->db->select('e.emp_no, e.birth_date, e.first_name, e.last_name, e.gender, e.hire_date')
        ->from('employees AS e')
        ->join('titles AS t', 'e.emp_no = t.emp_no')
        ->join('salaries AS s', 't.emp_no = s.emp_no')
        ->join('dept_emp AS de', 's.emp_no = de.emp_no')
        ->join('departments AS d', 'de.dept_no = d.dept_no')
        ->join('dept_manager AS dm', 'd.dept_no = dm.dept_no')
        ->limit($limit, $offset)
        ->order_by($sort_by, $sort_order)
        ->group_by('e.emp_no')
        ->where('t.title', 'staff'); 
于 2012-12-04T09:41:53.223 回答