我只想授予访问用户的主题主题,当管理员上传主题时,我将获取主题ID。然后通过一个视图文件,我试图将该主题的sid与该m-topic表中的一个sid匹配,因此我将一个表的值存储在变量$ rs中,并将值存储在$ ra中,然后在我的视图文件中使用if条件我的代码-
型号代码:
public function Select($Table, $Fields = '*', $Where = 1)
{
/*
* Select Fields
*/
if ($Fields != '*') {
$this->db->select($Fields);
}
/*
* IF Found Any Condition
*/
if ($Where != 1) {
$this->db->where($Where);
}
/*
* Select Table
*/
$query = $this->db->get($Table);
/*
* Fetch Records
*/
return $query->result();
}
控制器代码:
public function dashboard()
{
$data['rs'] = $this->lib_model->Select('v_subject_faculty_mapping', 'id,Subject,fid,sid', array('fid' => $this->session->EmpId, 'status' => 0 ));
$data['ra'] = $this->lib_model->Select('m_topic', 'id,sid,topic', array('status' => 0 ));
/*
* CK Editor
*/
$path = '../assets/ckfinder';
$width = '85%';
//Loading Library For Ckeditor
$this->load->library('ckeditor');
$this->load->library('ckfinder');
//configure base path of ckeditor folder
$this->ckeditor->basePath = base_url('assets/ckeditor/');
$this->ckeditor->config['toolbar'] = 'Full';
$this->ckeditor->config['language'] = 'en';
$this->ckeditor->config['width'] = $width;
//configure ckfinder with ckeditor config
$this->ckfinder->SetupCKEditor($this->ckeditor, $path);
$this->load->view('f/f_header',$data);
$this->load->view('f/dashboard');
$this->load->view('f/f_footer');
}
查看代码:
<label>Question Topic</label>
<select class="form-control" required name="S" id="S" style="border: double">
<option selected="">Select Topic</option>
<?php
if ($rs[sid] == $ra[sid]) {
# code...
foreach ($ra as $r)
{
?>
<option value="<?=$r->id;?>"><?=$r->topic;?></option>
<?php
}}
?>
</select>
</div>
您可以在模型中使用连接功能将这两个表连接在一起,然后不必检查分配课程的其他条件。在模型中尝试:
$this->db->select('t1.fields,t2.fields');
$this->db->from('user_table t1');
$this->db->join('course_table t2','t2.userid = t1.id'); // you can change the table name as per your database.
if ($Where != 1) {
$this->db->where($Where);
}
$query = $this->db->get();
return $query->result();
并且在控制器中只需调用上面在模型中编写的函数:
$data['rs'] = $this->lib_model->Select(array('fid' => $this->session->EmpId, 'status' => 0 ));
鉴于您不需要检查其他条件,您只需尝试使用foreach循环:
<?php foreach($rs as $r){ ?>
<option value="<?=$r->id;?>"><?=$r->topic;?></option>
<?php } ?>