2016-05-23 46 views
1

我已經工作,其具有從一個關聯數組填充這樣的下拉列表中的登記表上:插入選自下拉選項到分貝笨

 **<?php 
     **$options = array(
      'cbaringo' => 'Baringo', 
      'cbomet' => 'Bomet', 
      'cbungoma' => 'Bungoma', 
      'cbusia' => 'Busia', 
      'celgeyo' => 'Elgeyo Marakwet', 
      'cmigori' => 'Migori',** 
     ?>** 

我要插入的用戶選擇爲選擇數據庫如下

**$data = array(
      'scounty' => $this->input->post('counties'), 
      'ssubcounty' => $this->input->post('subcounty'), 
      'sname' => $this->input->post('dschoolname'), 
      'skcpecode' => $this->input->post('dkcpecode'), 
      'stelno' => $this->input->post('dtelno'), 
      'steampatronname' => $this->input->post('dpatroname'), 
      'steampatronemail' => $this->input->post('dpatronemail'), 
      'steampatrontelno' => $this->input->post('dpatrontelno'), 
      's_password' => $this->input->post('scpassword') 
     );** 

pupulated這樣的下拉:

**echo form_dropdown('counties', $options, 'cdefault');** 

以上行顯示的下拉列表中的選項如預期

 //inserted data into db 
     **$this->my_model->insert_data($data);** 

然而上插入鑰匙而不是從關聯數組值被插入到分貝。有什麼問題?

回答

0

你在選擇列表中看到的是不同的則是從它

$options = 
      // the value // what the user sees in the drop down 
array(
      'cbaringo' => 'Baringo', 
      'cbomet' => 'Bomet', 
      'cbungoma' => 'Bungoma', 
      'cbusia' => 'Busia', 
      'celgeyo' => 'Elgeyo Marakwet', 
      'cmigori' => 'Migori',** 
     ?> 

傳遞,因此,如果他們選擇巴林戈,傳遞的值應該是cbaringo值

+0

所以我應該怎麼做才能價值不是關鍵? – lil

+0

更改您的陣列。將cbarningo更改爲Baringo或任何你需要的。如果您在網頁上查看源代碼並查看選擇列表中的html代碼,這將更清晰。 – cartalot

+0

我通過在選擇標籤中使用選項標籤來解決此問題。謝謝你的提示 – lil