dortmundbvb0624 2015-11-19 09:16
浏览 13

如何使用选中的值更新多行并取消选中?

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();

        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错
    • ¥15 单片机学习顺序问题!!
    • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
    • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)