2014-03-19 157 views
4

我是codeignitor php developer.so,我需要發送數據庫多個複選框values.first所有我創建表與喜好,假期,設施和accomadation領域。表單提交多個複選框 - codeignitor

控制器

if($_POST) 
{ 
    $prefer= $this->input->post('prefer'); 
    $data['prefer'] = array(
      'prefer' => implode(",", $prefer), 
     ); 

    $holiday= $this->input->post('holiday'); 
    $data = array(
      'holiday' => implode(",", $holiday),  
     ); 
    $facility= $this->input->post('facility'); 
    $data = array(
      'facility' => implode(",", $facility),  
     ); 
    $accommodation= $this->input->post('accommodation'); 
    $data = array(
      'accommodation' => implode(",", $accommodation),  
     ); 

    $this->customize->save_customize_tour_detail($data); 
} 

視圖

野生及冒險
    <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="prefer[]" value="romantic" />Romantic & sensuous 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="prefer[]" value="healthy" />Healthy & rejuvenating 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="prefer[]" value="fun" />Fun & exciting 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="prefer[]" value="peaceful" />Thought provoking & peaceful 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="prefer[]" value="shopping" />Shopping 
         </label> 
        </div></div> 

        <div style="float:left"> 
        <label for=""><font color="#00CC66">What whould you like to see in a holiday?</font></label> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="holiday[]" value="beach" />Beaches 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="holiday[]" value="wild" />Wild life 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="holiday[]" value="fauna" />Fauna & flora 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="holiday[]" value="archeological" />Archeological sites 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="holiday[]" value="mountains" />Mountains & waterfalls 
         </label> 
        </div></div></div> 
        <br><br><br><br><br><br><br><br><br><br> 

        <div> 
        <div style="float:left; margin-right:30px;"> 

        <label for=""><font color="#00CC66">What is the most important facility you need?</font></label> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="facility[]" value="comfortable" />Comfortable accommodation 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="facility[]" value="transportation" />Transportation 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="facility[]" value="guide" />Guide assistance 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="facility[]" value="excellent" />Excellent food 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="facility[]" value="communication" />Communication 
         </label> 
        </div></div> 

        <div style="float:left"> 
        <label for=""><font color="#00CC66">What kind of accommodation pleases you?</font></label> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="accommodation[]" value="standard_duest_house" />Standard Guest Houses 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="accommodation[]" value="three_star" />3 Star Hotels 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="accommodation[]" value="five_star" />5 Star Hotels 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="accommodation[]" value="two_star" />2 Star Hotels 
         </label> 
        </div> 
        <div class="checkbox"> 
         <label> 

          <input type="checkbox" name="accommodation[]" value="four_star" />4 Star Hotels 
         </label> 
        </div> 

模型

function save_customize_tour_detail($data) { 
    $this->db->insert('ba_customize_tours',$data); 
} 

問題是,當我點擊發送按鈕只有accomadation值變爲table.others(喜歡,holoday,設施)值不會表.. 請幫我解決這個問題..

謝謝。

+0

試試這個 使用批量插入看到這個鏈接http://stackoverflow.com/questions/18015852/codeigniters-insert-batch-with-thousands-of-inserts -has-missing-records –

+0

使用insert_batch而不是插入。 – eronax59

回答

3

試試這個代碼:

if($_POST) 
{ 
    $prefer= $this->input->post('prefer'); 
    $data['prefer'] =implode(",", $prefer);   

    $holiday= $this->input->post('holiday'); 
    $data['holiday'] = implode(",", $holiday); 

    $facility= $this->input->post('facility'); 
    $data['facility'] = implode(",", $facility); 

    $accommodation= $this->input->post('accommodation'); 
    $data['accommodation'] = implode(",", $accommodation); 


    $this->customize->save_customize_tour_detail($data); 
} 
+1

這是完美的工作..非常感謝你的promp支持 – Harshan