我是php/codeignitor的新手,嘗試將表單複選框上的更改發佈到我的數據庫。要修改的行由下面的gl_id分配。 我不知道如何使用我的模型中的update_checked函數 後TRUE到這些字段中的每個gl_id = x和FALSE使用其餘字段不在數組中。我可以在控制器 中使用$ _POST ['checked']創建並查看選中值的數組,並將其傳遞給模型。現在我需要使用這個數組發佈到db,其中gl_id =視圖中表單的值。codeigniter更新數據庫的檢查項目爲「TRUE」,剩餘的未檢查項目爲「FALSE」
在View
<h1>Update GL id <?php echo $gl_field['gl_id'];?></h1>
<label>Stat</label>
<input type="checkbox" <?php if ($gl_field['stat'] == "TRUE") {echo "checked = checked";} ?>
name = "checked[]" id="stat" value= "stat" /><BR CLEAR="all">
<label>Exclude</label>
<input type="checkbox" <?php if ($gl_field['exclude'] == "TRUE") {echo "checked = checked";} ?>
name="checked[]" id="exclude" value= "exclude"><BR CLEAR="all">
<label>Override</label>
<input type="checkbox" <?php if ($gl_field['override'] == "TRUE") {echo "checked = checked";} ?>
name= "checked[]" id= "override" value = "override"/><BR CLEAR="all">
在控制器
public function update_table(){
$this->load->helper('form');
$this->page_nav_model->update_table();
$checked_array = $_POST['checked'];
$this->page_nav_model->update_checked($checked_array);
$this->load->view('pages/success');
}
在模型
foreach($checked_array as $true){
echo $true;
}
爲了澄清當我拉信息到表單在上面的例子中的所有複選框的是在數據庫中設置爲「TRUE」,以便檢查它們。如果我取消選中統計並點擊提交,我可以看到一個包含數值的數組(排除,覆蓋)。
我感謝任何幫助,使我朝着正確的方向前進。
感謝Tayler的解釋和功能。它工作得很好! – vizyourdata