我有点的新到MySQL/,请不要是粗鲁的。
我有一个名为"tbl_roguea“的表,其中包含列"unitassid”、"unitass“和"rankid”、“秩”。所有这些列都充满了如下信息:
tbl_roguea样品

现在,我有了另一个名为"tbl_rogueb“的表,用于计算所有的级别以及它们分配的位置。我的计数方法是调用一个执行插入的存储过程。如果我们与上表有关:
tbl_rogueb样品

现在,每当我在tbl_roguea中插入一行时,tbl_rogueb就会插入一行(如上面所示),tbl_roguea也会被计算在内,没关系。如果我更新列"unitassid“、"unitass”和"rankid“、”“,但不更改任何值,那么问题会怎样呢?如果我用相同的值更新了tbl_rogueb中的值,我如何不在tbl_roguea中插入另一行。
这是来自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)是(空)
rogueB_unit varchar(100)是(NULL)
rogueB_off_DIR int(11) YES 0
rogueB_off_CSUPT int(11) YES 0
rogueB_off_SSUPT int(11) YES 0
rogueB_off_SUPT int(11) YES 0
rogueB_off_CINSP int(11) YES 0
rogueB_off_SINSP int(11) YES 0
rogueB_off_INSP int(11) YES 0
rogueB_off_M int(11) YES 0
rogueB_off_F int(11) YES 0
rogueB_off_TOTAL int(11) YES 0
rogueB_noff_SFO4 int(11) YES 0
rogueB_noff_SFO3 int(11) YES 0
rogueB_noff_SFO2 int(11) YES 0
rogueB_noff_SFO1 int(11) YES 0
rogueB_noff_FO3 int(11) YES 0
rogueB_noff_FO2 int(11) YES 0
rogueB_noff_FO1 int(11) YES 0
rogueB_noff_M int(11) YES 0
rogueB_noff_F int(11) YES 0
rogueB_noff_TOTAL int(11) YES 0
rogueB_TOTAL_UP int(11) YES 0
rogueB_NUP_TOTAL int(11) YES 0
rogueB_NUP_M int(11) YES 0
rogueB_NUP_F int(11) YES 0
rogueB_TOTAL_OVERALL int(11) YES 0
rogueB_stamp varchar(100)是(NULL)
注:我不能再加一张照片了。很抱歉寄了这么长的邮筒。
发布于 2017-07-03 11:51:34
作为一名程序员,我可以建议使用选项2,这是一个很好的做法,让所有的逻辑在您的应用程序和使用数据库只是一个存储。在这种情况下,只需更改application/config/database.php中的数据库类型,就可以轻松地将数据库类型更改为与应用程序一起使用。
通常,如果选择选项2,则可以在sql表中添加status或creation_date/date_date列,并将逻辑基于这些值。这是一种版本控制,还有很多工作要做,但您可以使其可重用,并从应用程序的其他部分的代码中获得好处。
https://stackoverflow.com/questions/44824848
复制相似问题