2016-10-03 175 views
1

基本上我有三個表命名類,房間,hostel.this是我的表連接三個表,MySQL的

id name   daily_rent mon_rent facilities 
11 reservation  200   3000  reservation 
23 per1   100   1000  per1 
24 per2   100   1000  per2 
25 pamba1   100   1000  pamba1 
26 pamba2   100   1000  pamba2 

我的桌子的房間看起來像這樣

id rm_number capacity  bed_no     class hostel is_vaccant 
    34 1   5  1A,1B,1C,1D,1E    23  7  1 
    35 2   4  2A,2B,2C,2D     24  7  1 
    36 3   4  3A,3B,3C,3D     25  10  0 
    37 4   6  4A,4B,4C,4D,4E,4F   26  10  0 
    38 5   3  5A,5B,5C      23  7  1 
    39 6   8  6A,6B,6C,6D,6E,6F,6G,6H  25  10  1 

我hostel table看起來像這樣

id user_id  name type place address   phone username  password 
    7 78   periyar Girls tirur malappuram     periyar periyarhostel 
    10 81   pamba Boys tirur malappuram 04942569878  pamba pambahostel 

當我使用我的代碼,這樣

控制器

public function view_vaccancy() 
    { 
     $data['active_mn'] = 'view_vaccancy'; 
     if(! $this->ion_auth->logged_in() || !$this->ion_auth->is_admin()) 
     { 
      redirect('login'); 
     }  

    $data['class'] = $this->admin_model->get_all_vaccancy_list()->result(); 
    $data1=array(); 


    foreach ($data['class'] as $row) 
    { 
     $bed = $this->admin_model->bed_by_class_admin($row->id)->row(); 
     $res = $this->admin_model->get_admitted_room_admin($row->id); 
     $data1[] = $bed->capacity-$res; 
    } 
    $data['available'] = $data1; 

    $data['bed'] = $bed = $this->admin_model->bed_by_class_admin($row->id)->row(); 

    $data['form_url'] = ''; 
    $data['plc_hold'] = 'Name/ID'; 
    $this->load->view('admin/view_vaccancy',$data); 
} 

我的模型看起來像這樣

public function get_all_vaccancy_list() 
{ 
    $this->db->select('class.*,rooms.class,hostel.name as h_name'); 
    $this->db->join('rooms','class.id=rooms.class','left outer'); 
    $this->db->join('hostel','hostel.id=rooms.hostel'); 
    $query=$this->db->get('class'); 
    return $query; 


} 

,並即時得到我的輸出這樣的

SI no Hostel Class  Total Seat No. of Vaccancy 
    1  periyar per1   12  8 
    2  periyar per2   12  4 
    3  pamba  pamba1  12  8 
    4  pamba  pamba2  12  2 
    5  periyar per1   12  8 
    6  pamba  pamba1  12  8 

但我要必須像這樣得到它

SI no Hostel Class  Total Seat No. of Vaccancy 
    1  periyar per1   12   8 
    2  periyar per2   12   4 
    3  pamba  pamba1  12   8 
    4  pamba  pamba2  12   2 

和我的問題是在模型的任何猜測,解決提前

回答

1

此感謝你需要它組。

$this->db->group_by('hostel, class'); 
+0

謝謝你救了我的時間 –