PHP/MYSQL - 如何检测更新前列中的值是否仍然相同(codeigniter)

标签 php mysql codeigniter

我对 MySQL/PHP 有点新手,请不要粗鲁

我有一个名为“tbl_roguea”的表,其中包含列 “unitassid”、“unitass”和“rankid”、“rank”。所有这些列都填满了如下信息:

tbl_roguea 样本

enter image description here

现在我有另一个名为“tbl_rogueb”的表,用于计算所有排名以及它们分配的位置。我的计数方法是调用一个执行INSERT的存储过程。如果我们涉及上表:

tbl_rogueb 样本

enter image description here

现在,每当我在 tbl_roguea 中插入一行时,tbl_rogueb 都会插入一行(如上所示),并且 tbl_roguea 将被计数,没关系。 问题是如果我更新列“unitassid”、“unitass”和“rankid”、“rank”但不更改任何值会怎样。如果我用相同的值更新 tbl_roguea 中的值,我将如何不在 tbl_rogueb 中插入另一行。

这是 PHP 的示例代码:

public function rogueA_upGet()
    {
        $r_id = $this->input->post('mdl_a_id');
        $r_itemNR = $this->input->post('mdl_a_itemnr');

        $r_rankid = $this->input->post('mdl_a_rank');
        $r_rank = $this->input->post('hdmdl_rank');

        $r_lname = $this->input->post('mdl_a_lname');
        $r_fname = $this->input->post('mdl_a_fname');
        $r_mname = $this->input->post('mdl_a_mname');

        $r_desigid = $this->input->post('mdl_a_desig');
        $r_desig = $this->input->post('hdmdl_off');

        $r_unitassid = $this->input->post('mdl_a_unitass');
        $r_unitass = $this->input->post('hdmdl_uass');

        $r_dgov = $this->input->post('mdl_a_dgs');
        $r_dfir = $this->input->post('mdl_a_dfs');
        $r_lastp = $this->input->post('mdl_a_dlp');
        $r_dpprps = $this->input->post('mdl_a_DPPRPS');
        $r_daodco = $this->input->post('mdl_a_DPOD');
        $r_bday = $this->input->post('mdl_a_bday');
        $r_sa = $this->input->post('mdl_a_stat');

        $r_hitrainid = $this->input->post('mdl_a_hightr');
        $r_hitrain = $this->input->post('hdmdl_hitrain');

        $r_eligid = $this->input->post('mdl_a_elig');
        $r_elig = $this->input->post('hdmdl_elig');

        $r_educatt = $this->input->post('mdl_a_educatt');
        $r_sex = $this->input->post('mdl_a_sex');
        $r_relig = $this->input->post('mdl_a_rel');
        $r_civstat = $this->input->post('mdl_a_civstat');
        $r_add = $this->input->post('mdl_a_add');

        $data = array (
            'rogueA_itemNR' => $r_itemNR,

            'rogueA_rankid' => $r_rankid,
            'rogueA_rank' => $r_rank,

            'rogueA_lname' => $r_lname,
            'rogueA_fname' => $r_fname,
            'rogueA_mname' => $r_mname,

            'rogueA_desigid' => $r_desigid,
            'rogueA_desig' => $r_desig,

            'rogueA_unitass' => $r_unitass,

            'rogueA_dgov' => $r_dgov,
            'rogueA_dfir' => $r_dfir,
            'rogueA_lastp' => $r_lastp,
            'rogueA_dpprps' => $r_dpprps,
            'rogueA_daodco' => $r_daodco,
            'rogueA_bday' => $r_bday,
            'rogueA_sa' => $r_sa,
            'rogueA_educatt' => $r_educatt,

            'rogueA_eligid' => $r_eligid,
            'rogueA_elig' => $r_elig,

            'rogueA_hitrainid' => $r_hitrainid,
            'rogueA_hitrain' => $r_hitrain,

            'rogueA_sex' => $r_sex,
            'rogueA_relig' => $r_relig,
            'rogueA_civstat' => $r_civstat,
            'rogueA_add' => $r_add
            );

        $this->db->where('rogueA_id', $r_id);

            if($this->db->update('tbl_roguea',$data)){
                $this->trackermod->log_rA_update($log_itemNR,$log_comname);

                if($this->db->query('call rogue_A_update("'.$data['rogueA_id'].'","'.$data['rogueA_unitassid'].'")'))
                {
                    return true;
                }else {

                    if($data['rogueA_unitassid']  == '4' || $data['rogueA_unitassid']   == '5')
                        {
                            $this->db->query('call rogue_B_SusaMer("4","Emergency Medical & Rescue Services / Susana Heights Sub-Station");');
                        }
                    else if($data['rogueA_unitassid']  == '1' || $data['rogueA_unitassid']   == '2' ||$data['rogueA_unitassid']   == '3')
                        {
                            $this->db->query('call rogue_B("'.$data['rogueA_unitassid'] .'","'.$data['rogueA_unitass'] .'","'.$data['rogueA_unitassid'] .'");');
                        }
                    else
                        {
                            return false;
                        }
                        $this->db->query('CALL rogue_B_TOTAL();');
                        return true;

                }

            }
        else{
            return $this->db->error();
            return true;
            }
}

抱歉我的语法错误。非常感谢您回答我的问题。

<小时/>

编辑: “tbl_rogueb结构”

字段类型空键默认额外

<小时/>

rogueB_id int(11) 无 PRI (NULL) auto_increment
rogueB_unitid int(11) 是 (NULL)
rogueB_unit varchar(100) 是 (NULL)
rogueB_off_DIR int(11) 是 0
rogueB_off_CSUPT int(11) 是 0
rogueB_off_SSUPT int(11) 是 0
rogueB_off_SUPT int(11) 是 0
rogueB_off_CINSP int(11) 是 0
rogueB_off_SINSP int(11) 是 0
rogueB_off_INSP int(11) 是 0
rogueB_off_M int(11) 是 0
rogueB_off_F int(11) 是 0
rogueB_off_TOTAL int(11) 是 0
rogueB_noff_SFO4 int(11) 是 0
rogueB_noff_SFO3 int(11) 是 0
rogueB_noff_SFO2 int(11) 是 0
rogueB_noff_SFO1 int(11) 是 0
rogueB_noff_FO3 int(11) 是 0
rogueB_noff_FO2 int(11) 是 0
rogueB_noff_FO1 int(11) 是 0
rogueB_noff_M int(11) 是 0
rogueB_noff_F int(11) 是 0
rogueB_noff_TOTAL int(11) 是 0
rogueB_TOTAL_UP int(11) 是 0
rogueB_NUP_TOTAL int(11) 是 0
rogueB_NUP_M int(11) 是 0
rogueB_NUP_F int(11) 是 0
rogueB_TOTAL_OVERALL int(11) 是 0
rogueB_stamp varchar(100) 是 (NULL)

注意:我无法添加其他图片。很抱歉这篇文章很长。

最佳答案

作为一名程序员,我建议使用选项 2。将所有逻辑都放在应用程序中并使用数据库作为存储是一个很好的做法。在这种情况下,您只需更改 application/config/database.php 中的数据库类型即可轻松更改数据库类型以用于您的应用程序。

通常,如果您选择选项 2,您可以在 sql 表中添加 status 或creation_date/deletion_date 列,并根据这些值创建逻辑。这是某种版本控制,需要做很多工作,但您可以使其可重用,并从应用程序其他部分的该部分代码中受益。

关于PHP/MYSQL - 如何检测更新前列中的值是否仍然相同(codeigniter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44824848/

相关文章:

php - 我想先显示特色产品,然后应该显示其余产品 order by id desc

php - 使用 CodeIgniter + MySQL 更新选中的复选框

php在谷歌搜索中获取变量

mysql - 按两个不同列中的值对列求和

php - 从mysql数据库中的特定用户中选择数据到PHP

php - MySQL 连接,从一个表返回 1 行,并从另一个表返回多行作为数组或列表

php - 如何解决表单发布和 ajax 发布之间的奇怪冲突?

jquery - 我想将 ids 从模型($data)返回到 Controller

php - 2 循环填充的数据数组,如何将数据转为插入查询

php - 如何通过链接将值(value)转移到另一个页面?