Php 编辑时是否选中复选框显示
因为我经历了几个解决方案,所以我没有找到解决这个问题的方法。当我进行编辑并打开页面时,我希望显示插入时选择的标记复选框列表。 这是我的查看页面Php 编辑时是否选中复选框显示,php,codeigniter,checkbox,Php,Codeigniter,Checkbox,因为我经历了几个解决方案,所以我没有找到解决这个问题的方法。当我进行编辑并打开页面时,我希望显示插入时选择的标记复选框列表。 这是我的查看页面 <div class="form-group"> <label class="control-label col-sm-1" for="courses">Courses Completed</label> <div class=" col-sm-5">
<div class="form-group">
<label class="control-label col-sm-1" for="courses">Courses Completed</label>
<div class=" col-sm-5">
<input type="checkbox" name="select_course[]" id="select_course" value="10" <?php if($row->courses =='10') echo "checked" ;?>>10
<input type="checkbox" name="select_course[]" id="select_course" value="12" <?php if($row->courses =='12') echo "checked" ;?>>12
<input type="checkbox" name="select_course[]" id="select_course" value="degree" <?php if($row->courses=='degree') echo "checked" ;?>>degree
</div>
</div>
选中状态的属性为checked=“” 将php代码放在引号中
<input type="checkbox" name="select_course[]" id="select_course" value="degree" checked="<?php if($row->courses=='degree') echo "checked" ;?>" />
选中状态的属性为checked=“”
将php代码放在引号中
<input type="checkbox" name="select_course[]" id="select_course" value="degree" checked="<?php if($row->courses=='degree') echo "checked" ;?>" />
您应该输入以下代码:
<input type="checkbox" name="select_course[]" id="select_course" value="degree" <?php if($row->courses=='degree'): ?> checked="checked" <?php endif; ?> />
checked=“checked”/
您应该输入以下代码:
<input type="checkbox" name="select_course[]" id="select_course" value="degree" <?php if($row->courses=='degree'): ?> checked="checked" <?php endif; ?> />
checked=“checked”/
根据您发布的表格,您似乎在课程中存储逗号分隔的值,因此您需要在数组中转换并使用in_array()
函数进行检查
<div class="form-group">
<label class="control-label col-sm-1" for="courses">Courses Completed</label>
<?php $idArray = explode(",",$row->courses); ?>
<div class=" col-sm-5">
<input type="checkbox" name="select_course[]" id="select_course" rel="<?php echo $row->courses; ?>" value="10" <?php if(in_array('10',$idArray)) echo "checked" ;?>>10
<input type="checkbox" name="select_course[]" id="select_course" rel="<?php echo $row->courses; ?>" value="12" <?php if(in_array('12',$idArray)) echo "checked" ;?>>12
<input type="checkbox" name="select_course[]" id="select_course" rel="<?php echo $row->courses; ?>" value="degree" <?php if(in_array('degree',$idArray)) echo "checked" ;?>>degree
</div>
</div>
完成的课程
根据您发布的表,您似乎在课程中存储逗号分隔的值,为此,您需要在数组中转换并使用in\u array()
函数进行检查
<div class="form-group">
<label class="control-label col-sm-1" for="courses">Courses Completed</label>
<?php $idArray = explode(",",$row->courses); ?>
<div class=" col-sm-5">
<input type="checkbox" name="select_course[]" id="select_course" rel="<?php echo $row->courses; ?>" value="10" <?php if(in_array('10',$idArray)) echo "checked" ;?>>10
<input type="checkbox" name="select_course[]" id="select_course" rel="<?php echo $row->courses; ?>" value="12" <?php if(in_array('12',$idArray)) echo "checked" ;?>>12
<input type="checkbox" name="select_course[]" id="select_course" rel="<?php echo $row->courses; ?>" value="degree" <?php if(in_array('degree',$idArray)) echo "checked" ;?>>degree
</div>
</div>
完成的课程
是否可以打印$row->COURSESS显示print\r($row->courses)的输出代码>可以打印$row->courses显示print\r($row->courses)的输出代码>我已经这样给出了,但是所有的复选框都显示为marked@MOHAMMED您必须显示print\r($row->courses)的输出代码>给我们其他的智慧每个人只是猜测。把帽子输出在你的代码,然后我将不得不同意上述评论你需要打印的内容r($行->课程);这听起来像是从数据库中检索数据时出错,或者是从我的打印($row->COURCES)绘图时出错;看起来像我这样给出的“10,12”,但所有复选框都显示为marked@MOHAMMED您必须显示print\r($row->courses)的输出代码>给我们其他的智慧每个人只是猜测。把帽子输出在你的代码,然后我将不得不同意上述评论你需要打印的内容r($行->课程);这听起来像是从数据库中检索数据时出错,或者是从我的打印($row->COURCES)绘图时出错;看起来像这个“10,12”我用json_encode来插入值所以需要解码吗?我已经解码了,明白了…非常感谢..像这样改变了我用json_encode来插入值所以需要解码吗?我已经解码了,明白了…非常感谢..像这样改变了