0

i want to give access to only those subject's topics which are alotted to a user i'm taking subject id(sid) when admin upload topics . and by a view file i am trying to match that sid of topic to a from that m-topic table so i stored value og one table in a variale $rs and of secong on $ra and then used if condition in my view file here's my code --

Model code:

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();
    }

Controller code:

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');
}

View code:

                <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>
Soleil
  • 6,404
  • 5
  • 41
  • 61

1 Answers1

0

you can join this two tables using join function in model and then you dont have to check another conditions for allocated course. try this in model:

$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();

And in controller just call the function written above in model:

$data['rs'] = $this->lib_model->Select(array('fid' => $this->session->EmpId, 'status' => 0 ));

In view you dont need to check for extra conditions, you simply try using foreach loop:

<?php  foreach($rs as $r){ ?>

<option value="<?=$r->id;?>"><?=$r->topic;?></option>

<?php } ?>
  • thnx i am trying this – ansh singh Jun 05 '20 at 11:44
  • i hv one table with named as v_subject_faculty_mapping and second with m_topic i hv to match sid column ofboth table and show topic name from m_topic and suject name from v_suject_faculty_mapping . – ansh singh Jun 05 '20 at 11:50
  • you can use left join for better result. try by passing third parameter in join(). $this->db->join('course_table t2','t2.userid = t1.id','left'); – nikhil borikar Jun 08 '20 at 13:13