首页 > 解决方案 > 未返回 set_checkbox 值

问题描述

[在此处输入图像描述][1]我想在单击编辑按钮后使用编辑按钮重新填充我的表单,它将显示要显示的所有选定项目

<input type="checkbox" id="mycheck1" name="certid[]" 
  value="1" class="cbx"  <?php echo set_checkbox('certid','1');?>

控制器

   $data['getcert'] = $this->User_Model->getcert();

  output should be in the form of array 

   Array
  (
  [id] => 1
  [certificate_id] => 1
  [fee] => 500
  [APPNO] => 10001
  [regno] => 01107402042
  [certid] => 1
  [noc] => 2
  [paid] => 1000
  )


 <?php foreach($getcert as $student){ 
   echo '<pre>';
    print_r($student);
    echo '</pre>';
    ?>
 <td width="50px" align="center">1</td>
 <td>Transcripts  & Degree Certificate Attestation</td>
  <td align="center"><input type="checkbox" id="mycheck1" name="certid[]" 
   value="<?php echo (!isset($student['certid'])) ? 1 : $student['certid'] 
      ?>"
    class="cbx"  <?php echo set_checkbox('certid[]','1');?> ></td>
     <td> 500 </td>
    <td> <input type="number" id="primaryincome1"  min="1"  max="999" 
 name="noc[]" 
   value="<?php echo (!isset($student['noc'])) ? '' : $student['noc'] ?>"
   disabled> </td>
  <div class="col-xs-2">
    <td ><input type="text" id="totalamountremaining1"  name="txt" 
    class="text-right" value="<?php echo (!isset($student['paid'])) ? 0 : 
     $student['paid'] ?>"  size="5"></td>
      </div>

    that certid value only be placed in checkbox

此值存储在 db 中。如何在此视图中分配该值?

标签: phpcodeigniter

解决方案


尝试这个:

<input type="checkbox" id="mycheck1" name="certid[]" value="1" class="cbx" <?php echo set_checkbox('certid','1', $certid==1;?>>

作为您的$certid数据库值

从手册:

第三个(可选)参数允许您将项目设置为默认值(使用布尔值 TRUE/FALSE)'

所以你测试你的 db 值是否符合复选框值,就是这样。


推荐阅读