我添加記錄到我的數據庫,但是當我到達2條相同的記錄,並添加另一個相同的記錄雙打在數據庫中錄入的時間加倍。我想在我的數據庫中添加一條記錄,但記錄每次達到2個記錄
這裏是我的代碼:
$q = mysql_query("SELECT * FROM grade1 WHERE G1StudNo = '$_POST[cat]' AND G1SCode = '$_POST[subcat]' ");
while($noticia2 = mysql_fetch_array($q)) {
if(empty($noticia2['G1Sem']) AND empty($noticia2['G1Year'])){
mysql_query("UPDATE grade1 SET G1Sem = '$_POST[Sem]', G1Year = '$_POST[Year]'
WHERE G1StudNo = '$_POST[cat]' AND G1SCode = '$_POST[subcat]'");
}
else {
$query = mysql_query("SELECT * FROM curriculum WHERE SCode='$_POST[subcat]'");
while($noticia = mysql_fetch_array($query)) {
$insertSQL1 = mysql_query("INSERT INTO grade1 (G1StudNo, G1SCode, G1Sem, G1Year, Semester, YearLevel)
VALUES ('$_POST[cat]','$_POST[subcat]','$_POST[Sem]','$_POST[Year]','$noticia[Semester]','$noticia[YearLevel]')");
}
}
}
你的代碼是有點難以閱讀...你能正確格式化?此外,在您的查詢中,您不需要連接,因此您需要執行''。$ _ POST [cat]。''' – Bill 2011-02-25 19:23:02
對於錯誤的編碼約定感到抱歉.. – PiDO 2011-02-25 19:27:16