I have table structure like
id | user_id | notification_id | is_email_opted | is_sms_opted
1 88 10 0 0
1 88 12 1 0
I have checkboxes like
<td><h6>Work Order</h6></td>
<input type="checkbox" name="email_job" id="email_job">
<input type="checkbox" name="work_order_email" id="work_order_email" checked disabled value="1"></label></td>
<input type="checkbox" name="work_order_sms" id="work_order_sms" value="1"></label></td>
</tr>
I have to update these values into table according to user_id and notification_id. ALready i am inserting notificaiton values default when user signup. Also when checkboxed checked i am storing it in hidden value and send the values to php
<input type="hidden" name="sms_job_notify" id="sms_job_notify" value="0">
<input type="hidden" name="email_job_notify" id="email_job_notify" value="0">
<input type="hidden" name="work_order_sms_notify" id="work_order_sms_notify" value="0">
<input type="hidden" name="deal_email_notify" id="deal_email_notify" value="0">
I have tried with following php code to update it is working. the code is too complex
if($email_job || $sms_job ){
$update_data = array("is_email_opted"=>$email_job,"is_sms_opted"=>$sms_job);
$this->db->where("notify_type_id",10);
$this->db->where("user_id",$this->session->userdata('user_id'));
$this->db->update("user_notification", $update_data);
echo $this->db->last_query();
}else{
$update_data = array("is_email_opted"=>0,"is_sms_opted"=>0);
$this->db->where("notify_type_id",10);
$this->db->where("user_id",$this->session->userdata('user_id'));
$this->db->update("user_notification", $update_data);
echo $this->db->last_query();
}
if($work_order_sms ){
$update_data = array("is_sms_opted"=>$work_order_sms);
$this->db->where("notify_type_id",11);
$this->db->where("user_id",$this->session->userdata('user_id'));
$this->db->update("user_notification", $update_data);
echo $this->db->last_query();
}else{
$update_data = array("is_sms_opted"=>0);
$this->db->where("notify_type_id",11);
$this->db->where("user_id",$this->session->userdata('user_id'));
$this->db->update("user_notification", $update_data);
echo $this->db->last_query();
}