ID 在 mysql 后重置
ID reset in mysql
我尝试在 table 事件中重置我的 ID,但 query("UPDATE events SET ID=".$i."WHERE ID=".$row['ID'];)
总是失败。知道为什么吗?
//getting the whole table from mysql
$query="SELECT * FROM events";
$results=mysql_query($query);
$size=mysql_num_rows($results);
echo($size);
//drop the primary key
$query="ALTER TABLE events DROP PRIMARY KEY";
if(!(mysql_query($query)))
echo("Query1 failed");
//reset ID
for($i=0;$i<$size;$i++){
$row=mysql_fetch_assoc($results);
$query=" UPDATE events SET ID=".$i."WHERE ID=".$row['ID'];
if(!(mysql_query($query)))
echo("Query failed2");
}
//add primary key back to ID
$query="ALTER TABLE events ADD PRIMARY KEY (ID)";
if(!(mysql_query($query)))
echo("Query failed3");
你至少应该在WHERE
前加上一个space
$query=" UPDATE events SET ID=".$i." WHERE ID=".$row['ID'];
我尝试在 table 事件中重置我的 ID,但 query("UPDATE events SET ID=".$i."WHERE ID=".$row['ID'];)
总是失败。知道为什么吗?
//getting the whole table from mysql
$query="SELECT * FROM events";
$results=mysql_query($query);
$size=mysql_num_rows($results);
echo($size);
//drop the primary key
$query="ALTER TABLE events DROP PRIMARY KEY";
if(!(mysql_query($query)))
echo("Query1 failed");
//reset ID
for($i=0;$i<$size;$i++){
$row=mysql_fetch_assoc($results);
$query=" UPDATE events SET ID=".$i."WHERE ID=".$row['ID'];
if(!(mysql_query($query)))
echo("Query failed2");
}
//add primary key back to ID
$query="ALTER TABLE events ADD PRIMARY KEY (ID)";
if(!(mysql_query($query)))
echo("Query failed3");
你至少应该在WHERE
$query=" UPDATE events SET ID=".$i." WHERE ID=".$row['ID'];