【问题标题】:in code igniter i want to show only those subject's topic list to user which are alotted to the current user在代码点火器中,我只想向用户显示分配给当前用户的那些主题主题列表
【发布时间】:2020-06-05 10:13:04
【问题描述】:

我只想授予对那些在管理员上传主题时分配给用户的主题的访问权限。通过视图文件,我试图将主题的 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>

【问题讨论】:

  • 代码格式 + 拼写错误 + ...

标签: codeigniter codeigniter-3 codeigniter-2


【解决方案1】:

您可以使用模型中的连接功能连接这两个表,然后您不必检查分配课程的其他条件。 在模型中试试这个:

$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 } ?>

【讨论】:

  • 谢谢我正在尝试这个
  • i hv 一个名为 v_subject_faculty_mapping 的表,第二个名为 m_topic i hv 以匹配两个表的 sid 列并显示来自 m_topic 的主题名称和来自 v_suject_faculty_mapping 的主题名称。
  • 您可以使用左连接以获得更好的结果。尝试在 join() 中传递第三个参数。 $this->db->join('course_table t2','t2.userid = t1.id','left');
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-03
  • 1970-01-01
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多