I need to join three tables that acquires each other (not centralized to just a table)
1st table: attendance
---------------------------------------------------------------
| id | emp_code | emp_name | date | time |
| 001 | TNY | Tony |01.01.2001| 07.00 |
| 002 | PPR | Pepper |01.01.2001| 07.50 |
---------------------------------------------------------------
2nd table: employee
---------------------------------------------------------
| emp_code | emp_name |division_code| address |
| TNY | Tony | D001 | New york |
| PPR | Pepper | D002 | California|
---------------------------------------------------------
3rd table: division
-----------------------------
|division_code|division_name|
| D001 | Finance |
| D002 | Marketing |
-----------------------------
The result i want to get would be:
-----------------------------------------------------------------------------
| id | emp_code | emp_name |division_name| date | time |
| 001 | TNY | Tony | Finance |01.01.2001| 07.00 |
| 002 | PPR | Pepper | Marketing |01.01.2001| 07.50 |
-----------------------------------------------------------------------------
My code from my model:
function ShowData()
{
$this->db->select('attendance.emp_code, attendance.emp_name,division.division_name,attendance.date,attendance.time');
$this->db->from('attendance');
$this->db->join('employee', 'employee.emp_code = attendance.emp_code');
$this->db->join('division', 'employee.division_code = division.division_code');
$query = $this->db->get();
}
The result of my code is nothing, no data is shown, and i think it is because of my query
Your method isn't returning
anything:
$this->db->selct('a.id, a.emp_code, a.emp_name, d.divison_node, a.date, a.time');
$this->db->join('employee AS e', 'e.emp_code = a.emp_code');
$this->db->join('division AS d', 'd.division_code = e.division_code');
return $this->db->get('attendance AS a')->result();