简体   繁体   中英

Retrieve stored check box value from database

I have set of check boxes in my Privileges view.

<input type="checkbox" value="1" id="CheckBoxManageDevices"name="CheckBoxManageDevices" />Manage Tracking Devices
<input type="checkbox" value="2" id="CheckBoxMaps" name="CheckBoxMaps" />Manage Maps

I want to save the status of the check boxes (true or false) in the database and load the Privileges page with the updated values in the next time.

I was able to store the status of the check boxes using

$PriviledgeArray["BoxMaps"]=$this->input->post("CheckBoxMaps");

Now I want to fetch check box status to the Privileges page and show the check boxes are marked or unmarked depending on the database value. I have read that java script can be used to solve this but don't have a head start. Any hint will be highly appreciated.

<?php
$checkedMap="";
$checkedDevices="";
if($CheckBoxMaps==2){ // CheckBoxMaps from database
  $checked="checked";
}
if($CheckBoxManageDevices==1){ // CheckBoxManageDevices value from database
  $checkedDevices="checked";
}
?>

<input type="checkbox" value="1" id="CheckBoxManageDevices"name="CheckBoxManageDevices" <?php echo $checkedDevices;?> />
<input type="checkbox" value="2" id="CheckBoxMaps" name="CheckBoxMaps" <?php echo $checkedMap;?> />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM