在我的情況下,我做了兩個INSERT & UPDATE becoz我做了一個條件,如果一個選民已經投票了,它只會更新他的信息在我的tbl_initialVote表上。否則,它會插入。我如何以更新格式來做到這一點。請幫助...只是忽略變量$ voter .. thnks的冗餘。如何更新一個表的多行值
$mysqli->query("INSERT INTO `tbl_initialVote` (`studId`, `candId`)
VALUES ('".$voter."', '".$chairman."'),
('".$voter."', '".$vchairman."'),
('".$voter."', '".$secretary."'),
('".$voter."', '".$treasurer."')")
到Peterm
//this $getinfo is base on the logged in user
$getinfo = $mysqli->query("SELECT studId FROM`tbl_initialVote` WHERE studID = '".$voter."'");
if ($getinfo->num_rows > 0){
//here i know it got me error on this but this just i want to happen, make an update in the table if the user is already listed on my table. how could i suppose to do like [email protected]
$mysqli->query(UPDATE `tbl_initialVote` set candId = VALUES('".$chairman."', '".$vchairman."', '".$secretary."', '".$treasurer."')
} else {
$mysqli->query("INSERT INTO `tbl_initialVote` (`studId`, `candId`)
VALUES ('".$voter."', '".$chairman."'),
('".$voter."', '".$vchairman."'),
('".$voter."', '".$secretary."'),
('".$voter."', '".$treasurer."')")
}
你能否解釋多一點您的要求和說明它,包括所需的輸出,具有一定的樣本數據? – peterm
@peterm ..我更新了我的貼子代碼..希望你能找到我一個答案.. thnks提前.. –
對不起,它沒有讓它更清晰。 'tbl_initialVote'表是否有其他列?一旦插入數據,您如何區分主席和司庫? – peterm