Php 如何从数据库中选中复选框Codeigniter?

Php 如何从数据库中选中复选框Codeigniter?,php,mysql,database,codeigniter,checkbox,Php,Mysql,Database,Codeigniter,Checkbox,我这里有一些关于复选框的问题,如果单选按钮可以通过在视图中使用此脚本来解决 enter code here <input type="radio" name="jk" value="L" <?php echo set_radio('myradio', 'L', ($detail->jk == "L") ? TRUE : FALSE ); ?> >L <input type="radio" name="jk" value="P" <?php e

我这里有一些关于复选框的问题,如果单选按钮可以通过在视图中使用此脚本来解决

enter code here
   <input type="radio" name="jk" value="L" <?php echo set_radio('myradio', 'L', ($detail->jk == "L") ? TRUE : FALSE ); ?> >L

  <input type="radio" name="jk" value="P" <?php echo set_radio('myradio', 'P', ($detail->jk == "P") ? TRUE : FALSE ); ?>>P
在此处输入代码
>L
>P
但对于复选框,为什么不能使用此脚本解决此问题

enter code here

   <input type="checkbox" name="hoby" value="Lari" <?php echo set_checkbox('hoby', '($detail->hoby=="Lari")'); ?> />Lari

    <input type="checkbox" name="hoby" value="Berenang" <?php echo set_checkbox('hoby', '($detail->hoby=="Berenang")'); ?> />Berenang
在此处输入代码
/>拉里
/>贝雷南
我是“密码点火器”的新手

无论如何,非常感谢您的回答:D

试试这个:

<input type="checkbox" name="hoby" value="Lari" <?php echo set_checkbox('hoby', 'Lari')'); ?> />Lari

<input type="checkbox" name="hoby" value="Berenang" <?php echo set_checkbox('hoby', 'Berenang'); ?> />Berenang
JavaScript:

    function valueChanged() 
    {

        if(document.getElementById('hoby_l').checked == 'true')
        {


             document.getElementById('hoby_b').checked == 'false';
             return 1;
        }
        else
        {
              return 0;
        }

        if(document.getElementById('hoby_b').checked == 'true')
        {

             document.getElementById('hoby_l').checked == 'false';
             return 1;

        }
        else
        {
              return 0;
        } 

    }
一句真诚的忠告:你需要在提问时提高英语水平,否则社区很难帮助你。当你不能正确解释你的问题是什么时,你怎么能指望得到帮助

另一个真诚的建议是:无论看起来有多困难,请不要试图避开用户指南。你现在还不明白它的重要性。但这对你以后会有很大帮助

如果((int)$checked==1){//做你想做的事}
    if((int) $checked == 1){//do what you want}

    OR Try this

    create one funciton in your model file like this

    function get_checkbox_value($check) {

            for($i = 0; $i <= 6; $i++) {

                $result[$i] = '';

            }

            foreach($check as $chk) {

                for($i = 0; $i <= 6; $i++) {

                    if(($i+1) == $chk['ID']) {

                        $result[$i] = 'checked';

                        continue;

                    } 

                }

            }

            return $result;

        }
    and your view file call function like this


   <input type="checkbox" id="lari" name="hoby" value="2" <?php echo empty($check) ? '' : $check[1]; ?>/>
或者试试这个 在模型文件中创建一个函数,如下所示 函数get_checkbox_值($check){
对于($i=0;$i it’s not help mr,我已经阅读了关于helper的用户指南,但很难理解它!我希望在系统中显示时数据库中存储的所有内容都应该进行检查,我为愚蠢的问题感到抱歉,但实际上我是Code igniter的新手,我可以理解您的感受,但您必须参考标准参考ces.CodeIgniter用户指南就是为这个目的而设计的。另外,请让我知道我的解决方案是否有效。不起作用叔叔,如果有任何建议或脚本使其运行良好,请帮助我新月形月亮我仍然不明白,先生,你能解释更多吗,对不起,很难理解CodeIgniter,那么kueri将复选框称为它自己,是$ch吗艾克,对不起
    if((int) $checked == 1){//do what you want}

    OR Try this

    create one funciton in your model file like this

    function get_checkbox_value($check) {

            for($i = 0; $i <= 6; $i++) {

                $result[$i] = '';

            }

            foreach($check as $chk) {

                for($i = 0; $i <= 6; $i++) {

                    if(($i+1) == $chk['ID']) {

                        $result[$i] = 'checked';

                        continue;

                    } 

                }

            }

            return $result;

        }
    and your view file call function like this


   <input type="checkbox" id="lari" name="hoby" value="2" <?php echo empty($check) ? '' : $check[1]; ?>/>