2012-10-04 63 views
0

我是相當新的CI。我有一個存儲大量客戶信息的客戶數據庫。我還創建了更新控制器來更新當前客戶信息。更新表單與新客戶表單形式相同,但對於我從數據庫中提取舊數據的值。我的問題是它拉動所有的數據,並顯示在它的propor字段,除了下拉字段。任何想法如何解決這一問題?Codeigniter更新表單不檢索下拉值

控制器:

function edit_customer($id){ 
    $data['success']=0; 
    if($_POST){ 
     $data_customer=array(
      'first_name'=>$_POST['first_name'], 
      'last_name'=>$_POST['last_name'], 
      'phone'=>$_POST['phone'], 
      'email'=>$_POST['email'], 
      'website'=>$_POST['website'], 
      'business_name'=>$_POST['business_name'], 
      'business_add'=>$_POST['business_add'], 
      'business_cityState'=>$_POST['business_cityState'], 
      'cc_type'=>$_POST['cc_type'], 
      'cc_number'=>$_POST['cc_number'], 
      'cc_exp'=>$_POST['cc_exp'], 
      'cc_cvd'=>$_POST['cc_cvd'], 
      'billing_add'=>$_POST['billing_add'], 
      'billing_zip'=>$_POST['billing_zip'], 
      'package'=>$_POST['package'], 
      'assigned_zip_code'=>$_POST['assigned_zip_code'], 
      'active'=>1 
     ); 
     $data_customer['active'] = 1; 
     $this->customer->update_customer($id,$data_customer); 
     $data['success']=1; 
    } 
    $data['customer']=$this->customer->get_customer($id); 

    $this->load->view('header'); 
    $this->load->view('edit_customer',$data); 
    $this->load->view('footer'); 

} 

MODEL:

function update_customer($id, $data_customer){ 
    $this->db->where('id', $id); 
    $this->db->update('customers', $data_customer); 
} 

視圖下拉列表:

<label for="cc_type">Credit Card Type:</label> 
       <select name="cc_type" value="<?=$customer['cc_type'] ?>"> 
        <option></option> 
        <option>Visa</option> 
        <option>Mastercard</option> 
        <option>American Express</option> 
        <option>Discover</option> 
       </select> 

回答

1

對於一個選項被選中,您需要將selected屬性添加到<option>元素。

例如:

<select name="type"> 
    <option>a</option> 
    <option>b</option> 
    <option selected="selected">c</option> 
    <option>d</option> 
</select>​ 

景觀在這裏:http://jsfiddle.net/3M4xv/在你的代碼

所以,你可以做這樣的事情:

<select name="cc_type"> 
    <option <?php echo ($customer['cc_type']=='Visa')?'selected="selected"':''; ?>>Visa</option> 
    <option <?php echo ($customer['cc_type']=='Mastercard')?'selected="selected"':''; ?>>Mastercard</option> 
    <option <?php echo ($customer['cc_type']=='American Express')?'selected="selected"':''; ?>>American Express</option> 
    <option <?php echo ($customer['cc_type']=='Discover')?'selected="selected"':''; ?>>Discover</option> 
</select> 

希望它能幫助:)