简体   繁体   English

SQL多重连接不会在Codeigniter中返回所有行

[英]SQL multiple join does not return all rows in Codeigniter

This is my query: 这是我的查询:

$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'); 

I then return the array with this: 然后,我用这个返回数组:

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

        print_r ($ret['rows']);

All that is outputted is the emp_no: 输出的全部是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 ) )

How do I get to output all the selected columns? 如何输出所有选定的列?

PS: I have also tried to use result_array() nothing has worked. PS:我也尝试过使用result_array()没有任何效果。

You should combine all field names into one string instead of separating them as multiple parameters to select() function 您应该将所有字段名称组合为一个字符串,而不是将它们作为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'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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