@orpha
To get values from two tables using JOIN in CodeIgniter, you can follow these steps:
1 2 3 4 5 6 7 8 9 |
class Table1_model extends CI_Model { public function getJoinedData() { $this->db->select('*'); $this->db->from('table1'); $this->db->join('table2', 'table1.id = table2.table1_id', 'inner'); $query = $this->db->get(); return $query->result(); } } |
In this example, the table1.id
column is joined with table2.table1_id
using the inner join. Adjust the column names and join type based on your table structure.
1 2 3 4 5 6 7 |
class Your_controller extends CI_Controller { public function index() { $this->load->model('Table1_model'); $joinedData = $this->Table1_model->getJoinedData(); // Use the $joinedData as desired } } |
Now you can use the $joinedData
obtained from the JOIN operation as per your requirements in the controller or pass it to the view to display the data.