Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter join query multiple conditions don't work

I want to SELECT from my database table with a JOIN, but my attempt doesn't work.

My query:

$this->db->select();
$this->db->from('we');
$this->db->join('schedule', 'schedule.itemid = we.cid');
$this->db->join('schedule', 'schedule.itemtype = 'testitem'');
$this->db->where('we.isActive', 'Y');

This line makes problem with schedule.itemtype = 'testitem':

 $this->db->join('schedule', 'schedule.itemtype = 'testitem'');

How can I solve this?

like image 717
Pribill3399 Avatar asked Sep 01 '26 17:09

Pribill3399


1 Answers

You don't need to join same table twice. But just to extend ON clause:

$this->db->select();
$this->db->from('we');
$this->db->join('schedule', 'schedule.itemid = we.cid AND schedule.itemtype = \'testitem\'');
$this->db->where('we.isActive','Y');
like image 117
Alex Avatar answered Sep 03 '26 08:09

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!