简体   繁体   English

从数据库检索存储的复选框值

[英]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. 我读过Java脚本可用于解决此问题,但没有领先优势。 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;?> />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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