arrays - Collect all records from database and checked the exist -


i'm working in yii framework , have 1 problem . have 1 table amenities , want find all.

$amenities = roomtypeamenity::model()->findall(); command work fine .

then want find amenities have room , type $amenities_room = roomtypeamenity::model()->with('idroomtypeamenity')->findall(); , command work fine . when print amenities want checked exist amenities .

    foreach ($amenities $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  }?> 

use if else condition inside for-loop. check whether current amenity_room exists current amenity. if exits, checked checkbox.

foreach ($amenities $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  }?> 

hope helps!


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -