前一列中的值相同,我有點新到MySQL/PHP,請不要粗魯。PHP/MySQL的 - 如何檢測是否仍然更新(笨)
我有一個名爲「tbl_roguea」的表,它包含 「unitassid」,「unitass」和「rankid」,「rank」列。所有這些列都與信息填充這樣的:
tbl_roguea樣品
現在我有另一臺名爲「tbl_rogueb」爲計算所有的行列並在車站,他們被分配。我的計數方法是調用存儲過程,執行INSERT。如果我們關於以上表格:
tbl_rogueb樣品
現在,每當我在tbl_roguea插入一行,tbl_rogueb將插入一行(如上面),並且tbl_roguea將被計數,沒關係。 問題是什麼如果我更新列「unitassid」,「unitass」和「rankid」,「排名」,但不會更改任何值。如果我使用相同的值更新了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)NO 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 )YES 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)
注:我無法添加其他圖片。對不起,很長的職位。
感謝您的建議@Siniša。 也許我會盡量在稍後加強我的代碼。但很高興知道你的編程方式。對我而言,我認爲將這些代碼放在我的數據庫上會有更多的服務器流量。你不覺得嗎? – Quer
也許有點但這可以忽略不計。但還有一個更優雅的解決方案,我上次忘了提及。您可以使用Codeigniter驗證類(如果您使用的是Codeigniter)。以下是示例:https://www.codeigniter.com/userguide3/libraries/form_validation.html#cascading-rules。 –
是的!我正在使用CI!糾正我,如果我認爲是錯誤的, 我將使用'$ this-> form_validation-> set_rules('email','Email','required | valid_email | is_unique [users.email]');' * * is_unique **是我需要的,對吧? @Siniša – Quer