所以我想基於單參數更新我的表格:基於條件的更新表(While循環)
dateEntered字段必須爲空。
而且我要隨機選擇50行,並更新空白OWNERID領域的「測試」
以下是我有:
<?php
include("includes/constants.php");
include("includes/opendb.php");
$query = "SELECT * FROM contacts WHERE dateEntered='' ORDER BY RAND() LIMIT 50";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$firstid = $row['id'];
$query2 = mysql_query("UPDATE contacts
SET ownerID = 'Tester'
WHERE id = '$firstid'");
$result2 = mysql_query($query2) or die(mysql_error());
}
?>
它將更新一個記錄,然後退出並給我:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
選擇記錄的第一部分工作正常,其query2不會更新所有50條記錄,只有一個。也許我寫錯了。
嘗試調試$ QUERY2而 –
@MoyedAnsari內:他是通過輸出調試吧'mysql_error()' – xbonez
確定'ownerID'或'id'是類型'INT'的呢? – xbonez