我是Codeigniter的新手,我正尝试加入3表,但它给了一些问题

时间:2019-03-04 07:01:20

标签: php mysql sql codeigniter

enter image description here我有3个表,例如ts_usersts_acc_category ts_user 我正试图像这样

$this->db->select('*');

$this->db->from('ts_voucher');
$this->db->join('ts_users','ts_users.user_id = ts_voucher.id');
$this->db->join('ts_acc_category','ts_voucher.user_id = ts_acc_category.acc_cat_id');

$this->db->where('user_reg_type','bill_party');

错误是

<h1>A Database Error Occurred</h1>
        <p>Error Number: 1054</p><p>Unknown column 'ts_voucher.user_id' in 'on clause'</p><p>SELECT *
FROM `ts_voucher`
JOIN `ts_users` ON `ts_users`.`user_id` = `ts_voucher`.`id`
JOIN `ts_acc_category` ON `ts_voucher`.`user_id` = `ts_acc_category`.`acc_cat_id`
WHERE `user_reg_type` = 'bill_party'</p><p>Filename: models/reports/ExpensesModel.php</p><p>Line Number: 32</p> </div>

请告诉我我的代码在哪里错误

3 个答案:

答案 0 :(得分:2)

=>尝试一下。.

$this->db->select('tv.*,tu.*,tac.*'); //select field what you might want to select. 
        $this->db->from('ts_voucher as tv');
        $this->db->join('ts_users tu','tu.user_id = tv.id', 'left');
        $this->db->join('ts_acc_category as tac','tv.user_id = tac.acc_cat_id', 'left');
        $this->db->where('tv.user_reg_type','bill_party');

答案 1 :(得分:1)

$this->db->select('tv.*,tu.*,tac.*'); //select field what you might want to select. 
        $this->db->from('ts_voucher as tv');
        $this->db->join('ts_users tu','tu.user_id = tv.id', 'left');
        $this->db->join('ts_acc_category as tac','tv.user_id = tac.acc_cat_id', 'left');
        $this->db->where('tv.user_reg_type','bill_party');

答案 2 :(得分:1)

您在ts_voucher表中没有user_id字段,请先检查