本文介绍了如何使复选框状态基于数据库值处于选中还是未选中状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个如下表:-
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
我的表单如下:-
这是我创建表单的功能:-
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));
}
我的问题是:-
- 如果student_document_detail表中存在文档,则选中状态复选框.
-
如果不是,或者IsActive字段为0,则取消选中该复选框.
- if document exists in student_document_detail table then make status checkbox checked.
if not or IsActive field 0 then make checkbox unchecked.
如何根据这些条件生成文档上载表格.任何帮助表示赞赏!.预先感谢.
How to generate document upload form based on these conditions.Any help appreciated!. Thanks in advance.
推荐答案
尝试
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>;
}
这篇关于如何使复选框状态基于数据库值处于选中还是未选中状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!