@jasen
To join tables in CodeIgniter, you can use the active record feature provided by CodeIgniter's database library. Here is an example of how you can join two tables in CodeIgniter:
1 2 3 4 5 6 |
$this->db->select('*'); $this->db->from('table1'); $this->db->join('table2', 'table1.id = table2.table1_id'); $query = $this->db->get(); $result = $query->result(); |
In this example, we are selecting all columns from "table1" and joining it with "table2" on the condition that "table1.id = table2.table1_id". Once the query is executed, you can fetch the result using $query->result()
.
You can also specify the type of join (inner join, left join, right join) by passing it as the third parameter in the join
method. For example, to do a left join:
1
|
$this->db->join('table2', 'table1.id = table2.table1_id', 'left'); |
This is how you can join tables in CodeIgniter using the active record feature. It provides a convenient and secure way to build complex queries with ease.