How to join two database tables in codeigniter in query

To join the two or more database table in codeigniter we will user the codeigniter function join().

Syntax of join() function

<?php join('table_name' , 'condition'); //Syntax join('users' , 'users.user_id= user_record.user_id'); //Example ?> In the first parameter we will pass the name of the table , while at the second parameter we will pass the condition how to this join will accur. e.g users.user_id= user_record.user_id

Source Code

<?php $this->db->join('users', 'users.user_id= user_record.user_id'); $this->db->where('users.user_id','1'); $this->get('user_record'); ?> We can also write the code together using active links. <?php $this->db->join('users', 'users.user_id= user_record.user_id'). where('users.user_id = 1'). get('user_record'); ?>
Chapter Next »