dongwei1921 2015-08-24 04:27
浏览 133
已采纳

如何根据数据库值选中或取消选中复选框状态?

I have two tables like below:-

1. document_master                    
------------------                             
document_id   |  document_name      
------------------                             
1             | BirthCertifcate                 
2             | AadharCard      


2. student_document_detail                  
------------------                             
student_document_id |  student_id  | document_id | file_name | IsActive
------------------                             
1                   |     55       | 1           | 55_b.jpg    |    1  
2                   |     55       | 2           | 55_a.jpg    |    1
3                   |     70       | 2           |             |    0
4                   |     70       | 2           | 56_b.jpg    |    1

I have a form like below:- enter image description here

here is my function to create form:-

public function get_student_document_details(){
    if (!$this->input->is_ajax_request()) {
        exit('No direct script access allowed');
    }


    //here i want to check if document already in table or not on this basis make status checkbox checked or unchecked
    $student_document_records = $this->mdl_student_document_upload->get_student_document_list($student_id);

    //get the document master list
    $records = $this->mdl_student_document_upload->get_document_master_list();
    $document_master_list = '';
    $sr_no = 1;
    foreach($records as $row){
        $document_master_list .='<tr>
                                    <td>'.$sr_no.'</td>
                                    <td width="100"><span style="margin-top:0;" class="btn btn-default btn-file btn-xs">
                                                    Upload <input name="student_document" id="student_document" type="file">
                                                </span></td>
                                    <td width="100"><button  class="btn btn-xs btn-danger">Remove</button></td>
                                    <td>
                                    <input type="hidden" name="document_name" id="document_name" value="'.$row->DocumentName.'"/>
                                    <input type="hidden" name="document_master_id" id="document_master_id" value="'.$row->DocumentMasterID.'"/>
                                    '.$row->DocumentName.'
                                    </td>
                                    <td><input type="checkbox" name="status" id="status"/></td>
                                </tr>';
        $sr_no++;
    }
    die(json_encode($document_master_list));
}

My questions are:-

  1. if document exists in student_document_detail table then make status checkbox checked.
  2. if not or IsActive field 0 then make checkbox unchecked.

  3. How to generate document upload form based on these conditions. Any help appreciated!. Thanks in advance.

  • 写回答

5条回答 默认 最新

  • dsio68964998 2015-08-24 04:41
    关注

    Try

    if($row->IsActive==1)
    {
        echo '<td><input type="checkbox" checked="checked" name="status" id="status"/></td>';
    }
    else
    {
        echo '<td><input type="checkbox" name="status" id="status"/></td>;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵