如何通过我的更新表单输入中的id和视图获取数据信息

时间:2015-10-14 12:41:45

标签: php codeigniter

<div class="form-group">
    <label><?=lang('Students')?></label><br>
    <select name="students[]" id="students" class="form-control input-large select2" multiple>
       <?foreach($students as $student):?>
         <option value="<?=$student->student_id?>"><?=$student->student_surname.' '.$student->student_name.' '.$student->student_middlename?></option>
       <?endforeach?>
    </select>
</div>

问题可以查看多个选择输入中的所有数据,以便用户可以进行编辑。现在多个选择为空,用户应该再次选择

1 个答案:

答案 0 :(得分:1)

这是您要问的 - 在您编辑时显示多个选定项目?

查看 -

   <div class="form-group public-cus-form-field-wrap">
    <label for="treatment" class="col-sm-2 control-label">Treatment</label>
     <div class="col-sm-9">
        <select name="treatment[]" id="treatment" class="col-sm-12 country" style="height: 40px;" multiple="multiple">
        <option value="">--Select--</option>
           <?php
            if ($record->service_treatment)
            {

             $treat = explode(',',$record->service_treatment);
   //$record->service_treatment holds my selected values saved in db
             foreach($treatment as $treatments) // $treatment array holds the values to be displayed in select box
            { ?>
             <option value="<?php echo $treatments->treatment_name ?>" <?php if(in_array($treatments->treatment_name, $treat)){echo 'selected="selected"';}?> 
    ><?php echo $treatments->treatment_name; ?></option>
             <?php }  }
           else {  foreach($treatment as $treatments) { ?>
            <option value="<?php echo $treatments->treatment_name ?>"><?php echo $treatments->treatment_name; ?></option>
         <?php }     }    ?>            
    </select>
   </div>
 </div>

模型 -

public function name()
{
 if (is_array($this->input->post('treatment')))
    {
      $treatment = implode(",", $this->input->post('treatment'));
    }
    elseif($this->input->post('treatment')){

     $treatment = $this->input->post('treatment');
    }
// $treatment holds the multiple selected values
}