array_search result not getting properly
here i have two tables namely the rooms and student_hostel. rooms look like this
id rm_number capacity bed_no class hostel is_vaccant
40 1 5 1A,1B,1C,1D,1E 27 7 1
41 2 4 2A,2B,2C,2D 28 7 1
42 3 3 3A,3B,3C 29 10 1
43 4 4 4A,4B,4C,4D 30 10 1
44 5 6 5A,5B,5C,5D,5E,5F 27 7 1
45 6 7 6A,6B,6C,6D,6E,6F,6G 29 10 1
student_hostel looks like this
id first_name stud_id hostel class room bed status
175 siraj WPGH00175 7 28 41 2A P
176 nesru WPGH00176 7 28 41 2B P
180 dsf WPGH00180 7 27 40 1A G
Here is the code that i tried to get all occupied rooms
the controller looks like this
public function beds_occupied($rm)
{
$data['bed'] = $this->admin_model->ajax_bed($rm)->row();
$data['beds'] = explode(',',$data['bed']->bed_no);
$data['bed_no'] = $this->admin_model->get_bed_no($rm)->result();
foreach ($data['bed_no'] as $row)
{
if (($key = array_search($row->bed, $data['beds'])) !== false)
{
unset($data['beds'][$key]);
$data['beds'] = array_values($data['beds']);
}
}
return $data['beds'];
}
the model looks like this
public function ajax_bed($val=Null)
{
if(isset($val))
{
$this->db->where('id',$val);
}
return $this->db->get('rooms');
}
public function get_bed_no($id)
{
return $this->db->get_where('student_hostel',array('room'=>$id));
}
the ouput iam getting is all vaccant beds instead of occupied, the result iam getting is like this.
SI no Rooms Class Hostel Occupied
1 1 periyar1 periyar 1B,1C,1D,1E
2 2 periyar2 periyar 2C,2D
3 3 pamba1 pamba 3A,3B,3C
4 4 pamba 2 pamba 4A,4B,4C,4D
5 5 periyar1 periyar 5A,5B,5C,5D,5E,5F
6 6 pamba1 pamba 6A,6B,6C,6D,6E,6F,6G
but i want to get it like this
SI no Rooms Class Hostel Occupied
1 1 periyar1 periyar 1A
2 2 periyar2 periyar 2A,2B
3 3 pamba1 pamba
4 4 pamba 2 pamba
5 5 periyar1 periyar
6 6 pamba1 pamba