[eluser]darkhouse[/eluser]
You're on the right track, at least your database looks to be setup correctly. Try this in your model:
Code:
function search($name){
$this->db->select('c.*, s.name service_name');
$this->db->join('services_bundles sb', 'sb.customer_id c.id');
$this->db->join('services s', 's.id = sb.service_id');
$this->db->like('c.name', $name);
$query = $this->db->get('customers c');
return $query->result();
}
So, if you run $your_model->search('Brian'), that will give you 2 records:
Code:
Array(
[0] => Object(
id => 1,
name => Brian,
service_name => Phone
),
[1] => Object(
id => 1,
name => Brian,
service_name => Internet
)
)
Or, you could do it in 2 queries, like this:
Code:
function search($name){
$this->db->like('name', $name);
$query = $this->db->get('customers', 1);
$row = $query->row();
$this->db->join('services s', 's.id = sb.service_id');
$this->db->where('sb.customer_id', $result->id);
$query = $this->db->get('services_bundles sb');
$row->services = $query->result();
return $row;
}
So that would give you just 1 row, but an array of that customer's services also, like this:
Code:
Object(
id => 1,
name => Brian,
services => Array(
[0] => Object(
id => 1,
name => Phone
),
[1] => Object(
id => 2,
name => Internet
)
)
)