如何根据数据库值选中或取消选中复选框状态?
我有两张桌子如下: –
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
我的表格如下: –
这是我创建表单的function: –
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 .=' '.$sr_no.' Upload DocumentName.'"/> DocumentMasterID.'"/> '.$row->DocumentName.' '; $sr_no++; } die(json_encode($document_master_list)); }
我的问题是: –
- 如果student_document_detail表中存在文档,则选中make status复选框。
-
如果不是或IsActive字段0然后取消选中复选框。
-
如何根据这些条件生成文档上载表单。 任何帮助表示赞赏! 提前致谢。
尝试
if($row->IsActive==1) { echo ' '; } else { echo ' ; }
做这样的事情。
试试这个
IsActive==1) { echo "checked" } ?> name="status" id="status"/>
你可以尝试这个来检查它是否活跃的天气
IsActive==1) ? "checked": '' ;?> name="status" id="status"/>
注意
我用过短的if else。 如果不熟悉,你可以了解更多关于此的信息
试试今年5月它会帮助你
if($row->IsActive==1) { } else{ }