所以我试图根据一个参数更新我的表:
dateEntered 字段必须为空。
我想随机选择 50 行,并将空白的 ownerID 字段更新为“Tester”
这是我所拥有的:
<?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 条记录,只有一条。也许我写错了。