codeigniter - 在代码点火器中,我只想向用户显示分配给当前用户的那些主题的主题列表
问题描述
我只想授予访问权限,这些主题在管理员上传主题时分配给我正在使用主题 id(sid) 的用户。并且通过视图文件,我试图将主题的 sid 与该 m-topic 表中的 a 匹配,因此我将值 og 一个表存储在变量 $rs 和 $ra 上的 secong 中,然后在我的视图文件中使用 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 } ?>
推荐阅读
- python - 使用 markovify 生成押韵的歌词
- php - 我是否需要特定的东西才能使标头位置功能正常工作?
- c++ - 为什么在运行“make”命令后在 ns2 中修改 *.cc 文件没有任何变化
- vue.js - Vuejs 中“vue-table-2”组件的“挂载组件失败”错误
- matlab - 在 Simulink 中查看导入的 FMU/FMI 模块的代码?
- python - Ansible 错误:赋值前引用了局部变量“值”
- php - 功能:如何在 switch 和 foreach 中传递参数?
- r - R:删除(rm)一个变量,其中该变量的名称是存储在另一个变量中的字符串
- node.js - 在 godaddy 共享主机上永远运行 node/express 应用程序
- r - 如何从使用 R 定义 3 个级别的现有列形成 1 列?