I’m having an function which gets data from my database, and joins different tables. This is the method:
public function getCallcenterCall() {
$this->db->select('bedrijf.*, status.status_naam, quickscan.datum_verzonden');
$this->db->join('quickscan', 'bedrijf.id = quickscan.bedrijf_id');
$this->db->join('status', 'bedrijf.status = status.status_id');
$this->db->where('status', '0');
$query = $this->db->get('bedrijf');
return $query->num_rows() > 0 ? $query-> result_array() : FALSE;
}
In the table status I got 3 rows: 'id', 'status_id', 'status_naam'. In my view, I output the status_naam, but here it gets wrong.
Instead of giving me the 'status_naam' that belongs to 'status_id=0'; it gives me the 'status_naam' where 'status_id=1'.
The same thing happens if I try to get the 'status_naam' for 'status_id=1' then it gives me the 'status_naam' from 'status_id=2'.
What am I doing wrong? Thanks in advance!
Is your database setup to use foreign key constraints?
simple example :
Tables
Raw SQL
As you can see you set an index of
group_idon the users table,then set it as our foreign key and tell it to reference the
groupsid.innodb engine is required & the rows must match identically.
…hope that makes sense