dongluan7821 2017-07-15 07:56
浏览 47

如何创建复选框检查codeigniter中的数据库中是否存在值?

code:

<?php
    foreach ($college_id as $fetch) 
    {
        $facility=explode(",",$fetch['facilities']);
        foreach ($facility as $key) 
        {
            $facilities = $key;
        }
    }
?>

<input type='checkbox'  name='facilities[]' value='Gym' <?php if(in_array("Gym",$facilities)) { ?> checked="checked" <?php } ?>> &nbsp; Gym
<input type='checkbox'  name='facilities[]' value='Boys Hostel' <?php if(in_array("Boys Hostel",$facilities)) { ?> checked="checked" <?php } ?>> &nbsp; Boys Hostel
<input type='checkbox'  name='facilities[]' value='Girls Hostel' <?php if(in_array("Girls Hostel",$facilities)) { ?> checked="checked" <?php } ?>> &nbsp; Girls Hostel
<input type='checkbox'  name='facilities[]' value='Scholarship' <?php if(in_array("Scholarship",$facilities)) { ?> checked="checked" <?php } ?>> &nbsp; Scholarship

In this code I have multiple checkbox and value are exist in database. Now, I want to check checkbox if value exist in database. So, How can I do this ? Please help me.

Thank You

  • 写回答

3条回答 默认 最新

  • dtnnpt11795 2017-07-15 09:13
    关注

    You can try this code.

    <?php
        $college_id = array('facilities'=> array('Gym', 'Boys Hostel'));
    ?>
    
     <input type='checkbox'  name='facilities[]' value='Gym' <?php if(in_array("Gym",$college_id['facilities'])) { ?> checked="checked" <?php } ?>> &nbsp; Gym
     <input type='checkbox'  name='facilities[]' value='Boys Hostel' <?php if(in_array("Boys Hostel",$college_id['facilities'])) { ?> checked="checked" <?php } ?>> &nbsp; Boys Hostel
    <input type='checkbox'  name='facilities[]' value='Girls Hostel' <?php if(in_array("Girls Hostel",$college_id['facilities'])) { ?> checked="checked" <?php } ?>> &nbsp; Girls Hostel
    <input type='checkbox'  name='facilities[]' value='Scholarship' <?php if(in_array("Scholarship",$college_id['facilities'])) { ?> checked="checked" <?php } ?>> &nbsp; Scholarship
    

    Gym and Boys Hostel checkbox will be checked.

    Cheers!!

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大