0

Hi any one help me how to get data in drop down from database in codeigniter.below is my code it is not work working. The below code is not working properly the drop down not appearing when click please help me to get data. I am doing it in codeigniter. I want to get data from database in dropdown. I think the code is perfect am new to codeigniter the below code is not working properly the drop down not appearing when click please help me to get data. I am doing it in codeigniter. I want to get data from database in dropdown. I think the code is perfect am new to codeigniter

Model:

public function getdepartment() {
     $query = $this->db->query("select department from object_data");
     $result = $this->executeSelectQuery($query);
     return $result;
}

View:

<div class="col-md-4">
    <h4> Courses:</h4>
    <?php $dp = $this->base_model->getdepartment(); ?>
</div>
<div class="col-md-8">
      <select name="report_type" class="form-control">
      <?php foreach($dp as $row) { 
            echo '<option value="'.$row->department.'">'.$row->department.'</option>';
      }?>
      </select>
</div>

Controller:

public function employe() {
     $data['title'] = 'title'; 
     $this->load->model('base_model');
     $data['groups'] = $this->base_model->getCourseAll();
     $data['dprtmnt'] = $this->base_model->getdepartment();
     $this->load->view('employe', $data);
}

the above code is not working properly the drop down not appearing when click please help me to get data

1

2 Answers 2

0

Model

 public function getdepartment() {
 $query = $this->db->query("select department from object_data");
 return $query->result();
 }

controller

 public function employe() {
 $data['title'] = 'title'; 
 $this->load->model('base_model');
 $data['groups'] = $this->base_model->getCourseAll();
 $data['dprtmnt'] = $this->base_model->getdepartment();
 $this->load->view('employe', $data);
 }

views

<div class="col-md-4">
<h4> Courses:</h4>
<?php $dp = $this->base_model->getdepartment(); ?>
</div>
<div class="col-md-8">
  <select name="report_type" class="form-control">
  <?php foreach($dprtmnt as $row) { 
        echo '<option value="'.$row->department.'">'.$row-
 >department.'</option>';
  }?>
  </select>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

you should try codeigniter own methods it is the good way for practice.

Model :

public function getdepartment() {
     $query = $this->db->select('department')->from('object_data')->get();
     return $query->result();
 }

Controller :

public function employe() {
     $data['title'] = 'title'; 
     $this->load->model('base_model');
     $data['groups'] = $this->base_model->getCourseAll();
     $data['dprtmnt'] = $this->base_model->getdepartment();
     $this->load->view('employe', $data);
 }

Views :

<select name="report_type" class="form-control">
    <?php foreach($dprtmnt as $row) { 
      echo '<option value="'.$row->department.'">'.$row-
>department.'</option>';
    }?>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.