我想更新從數組中獲取的表中的值。我沒有得到任何錯誤,但它並沒有更新我的表ex_test_setting。我究竟做錯了什麼?我跟着其他帖子和谷歌搜索,但我不能得到一個正確的答案。PHP更新數組中的值
echo "<strong>Checking if the test points changed</strong>";
echo "</BR>";
$getTotalPoints = mysql_query("SELECT SUM(points_available) FROM ex_question WHERE test_name = '$tid_mod1'") or die(mysql_error());
$totalPoints = mysql_fetch_array($getTotalPoints);
echo "New points for test: " . $totalPoints['SUM(points_available)'];
echo "</BR>";
$sql2="SELECT DISTINCT point FROM ex_test_setting WHERE testid = '$tid_mod1'";
$res2=mysql_query($sql2);
while($row2 = mysql_fetch_array($res2)) {
$point1=$row2['point'];
echo "Old points for test: " . $point1;
echo "</BR>";
}
if ($totalPoints['SUM(points_available)'] <> $point1) {
echo "Updating...";
$newpoint = $totalPoints['SUM(points_available)'];
echo $newpoint;
mysql_query("UPDATE ex_test_setting SET point = '$newpoint' WHERE test_name = '$tid_mod1'");
}
那是什麼'<>'? – jmishra 2012-03-14 10:04:05
當你運行'echo $ newpoint'這行時,你有沒有得到任何值?還有什麼'ex_test_setting'表的結構? ..最後,最好寫'SELECT SUM(points_available)AS sum1',這樣你就可以得到'$ totalPoints ['sum1']' – Ashraf 2012-03-14 10:06:12
@ ladiesMan217的值,它通常在PHP中使用,就像'!=' – Ashraf 2012-03-14 10:07:22