如何从CodeIgniter

时间:2017-11-03 03:57:41

标签: php mysql codeigniter

任何人都帮我如何从codeigniter中的数据库中下载数据。我的代码是不能正常工作的。以下代码无法正常工作,点击时不显示下拉请帮我获取数据。我在codeigniter中这样做。我想从下拉列表中获取数据库中的数据。我认为代码是完美的新代码签名以下代码不能正常工作下拉不出现时点击请帮助我获取数据。我在codeigniter中这样做。我想从下拉列表中获取数据库中的数据。我认为代码是完美的代码生成器

型号:

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

查看:

<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>

控制器:

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

以上代码无法正常工作,点击时不显示下拉请帮我获取数据

2 个答案:

答案 0 :(得分:0)

模型

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

控制器

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

视图

<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>

答案 1 :(得分:0)

你应该尝试使用codeigniter自己的方法,这是练习的好方法。

  

型号:

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

控制器:

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

观点:

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