被髮送到數據庫作爲「0」這是我的看法如何設置複選框的值,如果該複選框未選中的值將在笨
<div class="checkbox checkbox-info checkbox-inline">
<input type="checkbox" name="box" id="busy" <?=($restaurant_info["restaurant_busy"] != 0)? "checked":""?>/>
<label for="busy">Busy</label>
</div>
<br><br>
<div class="row">
<div class="col-md-6">
<select id="dropdownHolder" name="restaurant_busy">
<option value="1" <?php if ($restaurant_info["restaurant_busy"] == '1') echo 'selected = "selected"'; ?>>30 minute</option>
<option value="2" <?php if ($restaurant_info["restaurant_busy"] == '2') echo 'selected = "selected"'; ?>>60 minute</option>
<option value="3" <?php if ($restaurant_info["restaurant_busy"] == '3') echo 'selected = "selected"'; ?>>90 minute</option>
<option value="4" <?php if ($restaurant_info["restaurant_busy"] == '4') echo 'selected = "selected"'; ?>>120 minute</option>
</select>
</div>
</div>
這是我的jquery:
$(function() {
var selected = $('#dropdownHolder option:selected'), // Seems to be unused
$busy = $('#busy'), // Always cache your queries
$dropdown = $('#dropdownHolder'); // Caching queries
$dropdown.hide(); // Hidden by default initially
$busy.change(function() {
if ($busy.prop('checked')) {
$dropdown.show().focus().click();
} else{
$busy.prop('checked', false);
$dropdown.blur().hide();
}
});
$busy.change(); // This sets initial state
});
$("#edit_restaurant").submit(function() {
$("#edit_restaurant").attr('action', '/VENDOR/Vendor/change_restaurant/');
this.submit();
});
這裏是我的更新
function change_restaurant(){
if(!isset($_COOKIE["vendor_login"])){ redirect("/VENDOR",'refresh'); }
if(!$this->Token_m->m_check_token($this->input->cookie('vendor_login'),$this->input->cookie('vendor_token'))){
setcookie('vendor_login', '', time() - 3600, '/');
redirect('/VENDOR/',"refresh");
}
if ($this->input->cookie('vendor_login') != null) {
$admin_name = $this->input->cookie('vendor_login');
setcookie('vendor_login', $admin_name, time() + 28800, '/');
$msg = $this->input->cookie('vendor_token');
setcookie('vendor_token', $msg, time() + 28800, '/');
}
if($vendorname = $_COOKIE["vendor_login"]) {
$check_login = $this->Vendor_m->m_get_user_by_vendor($vendorname);
$restaurant_id = $check_login["restaurant_id"];
{
if ($_POST == NULL){
redirect("/VENDOR/Vendor/vendor_setting","refresh");
}
$data = array(
"restaurant_busy" =>$this->input->post("restaurant_busy"),
"restaurant_active" =>$this->input->post("restaurant_active"),
"delivery_active" =>$this->input->post("delivery_active"),
"takeaway_active" =>$this->input->post("takeaway_active"),
"voucher_active" =>$this->input->post("voucher_active"),
);
$this->Vendor_m->m_update_restaurant_info($data,$restaurant_id);
}
}redirect("/VENDOR/Vendor/vendor_setting","refresh");
}
控制器,這是我的模型
功能m_update_restaurant_info($數據,$ restaurant_id) {
$this->db->where("restaurant_id", $restaurant_id);
$this->db->update("uhd_restaurant", $data);
}
值1, 2,3和4來自下拉菜單,並帶有數據庫表fie ld的名字是「restaurant_busy」,我想如果複選框沒有被選中,將會更新爲「0」值到restaurant_busy,我可以幫助我嗎?
你能告訴我怎麼做嗎?,我認爲這是我的回答什麼即時通訊試圖找到@moped –