下拉选择值未保存在数据库中

时间:2019-09-02 05:01:38

标签: codeigniter codeigniter-3

我是Codeigniter的新手,并创建了一个项目,其中下拉列表从表1中获取数据,我想将数据保存至表2。但是,另一个值选项是保存而不是下拉值。代码如下。

型号:

function getPriviousScore() {
    $this->db->select('*');
    $this->db->from('ielts_previous_score');
    $query = $this->db->get();
    return $query->result_array();
}

控制器:

$data['ielts_previous_score'] = $this->enquiry_model->getPriviousScore();

查看:

<select name="ielts_previous_score" class="form-control">
    <option value=""><?php echo $this->lang->line('select'); ?></option>  
    <?php foreach ($ielts_previous_score as $key => $value) { ?>
        <option value="<?php print_r($value['ielts_previous_score']); ?>" <?php if (set_value('ielts_previous_score') == $value['ielts_previous_score']) { ?>selected=""<?php } ?>><?php print_r($value['ielts_previous_score']); ?></option>
    <?php } ?>                                       
</select>

1 个答案:

答案 0 :(得分:0)

模型

  function getPriviousScore() {
    $this->db->select('*');
    $this->db->from('ielts_previous_score');
    $query = $this->db->get();
    return $query->result_array();
  }

控制器

   $data['ielts_previous_score'] = $this->enquiry_model->getPriviousScore();

查看

 <select name="ielts_previous_score" class="form-control">
 <option value=""><?php echo $this->lang->line('select'); ?></option>  
 <?php foreach ($ielts_previous_score as $key => $value) { ?>
    <option value="<?php echo $value['ielts_previous_score']; ?>" <?php if 
    (set_value('ielts_previous_score') == $value['ielts_previous_score']) { ? 
  >selected=""<?php } ?>><?php echo $value['ielts_previous_score']; ?></option>
 <?php } ?>
 </select>