2013-05-14 86 views
0

我在Yii框架中工作,我有一個問題。 我有一張桌子和設施,我想找到一切。從數據庫收集所有記錄,並檢查存在

$ amenities = RoomTypeAmenity :: model() - > findAll(); 此命令正常工作。

然後我想找到這個房間有什麼設施,然後輸入 $ amenities_room = RoomTypeAmenity :: model() - > with('idRoomTypeAmenity') - > findAll(); 而這個命令工作正常。但是,當打印的設施我想檢查存在的設施。

foreach ($amenities as $amenity) { ?> 
     <input type="checkbox" class="css-checkbox" id="facility_<?php echo $amenity->id_room_type_amenity; ?>"> 
     <label class="css-label" for="facility_<?php echo $amenity->id_room_type_amenity; ?>"><?php echo $amenity->name; ?></label> 

     <?php }?> 

回答

1

使用if else條件裏面for-loop。檢查目前的舒適度是否存在當前舒適度_空間。如果退出,則checkedcheckbox

foreach ($amenities as $amenity) { ?> 
    if($amenity->id_room_type_amenity!=null){ 
     <input type="checkbox" class="css-checkbox" id="facility_<?php echo $amenity->id_room_type_amenity; ?>" checked> 
     <label class="css-label" for="facility_<?php echo $amenity->id_room_type_amenity; ?>"><?php echo $amenity->name; ?></label> 
    } else { 
     <input type="checkbox" class="css-checkbox" id="facility_<?php echo $amenity->id_room_type_amenity; ?>"> 
     <label class="css-label" for="facility_<?php echo $amenity->id_room_type_amenity; ?>"><?php echo $amenity->name; ?></label> 
    } 

<?php }?> 

希望這有助於!

相關問題