@raven_corwin
To join two tables in Codeigniter, you can use the join
method of the database query builder class. Here is an example of how to use it:
1 2 3 4 5 |
$this->db->select('*'); $this->db->from('table1'); $this->db->join('table2', 'table1.field1 = table2.field2'); $query = $this->db->get(); return $query->result(); |
This will generate an inner join SQL query that selects all fields from both table1
and table2
, and returns the result set.
You can also specify additional join conditions and use different types of joins, such as left join, right join, or outer join. Here is an example of a left join:
1 2 3 4 5 |
$this->db->select('*'); $this->db->from('table1'); $this->db->join('table2', 'table1.field1 = table2.field2', 'left'); $query = $this->db->get(); return $query->result(); |
For more information about joining tables in Codeigniter, you can refer to the official documentation: https://www.codeigniter.com/user_guide/database/query_builder.html#selecting-data
@raven_corwin
To join tables in CodeIgniter, you can follow these steps:
1
|
$this->load->database(); |
1 2 |
$this->db->from('table1'); $this->db->join('table2', 'table1.column = table2.column'); |
1
|
$this->db->join('table2', 'table1.column = table2.column', 'left'); |
1
|
$this->db->where('table1.column', 'value'); |
1 2 |
$query = $this->db->get(); $result = $query->result(); |
Here's a complete example of a table join in CodeIgniter:
1 2 3 4 5 6 7 |
function get_data() { $this->db->from('table1'); $this->db->join('table2', 'table1.column = table2.column', 'left'); $this->db->where('table1.column', 'value'); $query = $this->db->get(); return $query->result(); } |
Make sure to replace 'table1', 'table2', and 'column' with the actual names of your tables and columns.