我在更新特定列时遇到问题。我不想指定ID以更新该行。我正在使用像旗帜。例如,我想将列'请求'更改为1.最初它是0.我使用此代码它确实已更改但不是我想要的ID。假设我点击ID = 2,但它会更新ID = 3的列''request'。我的问题是什么。帮我。被困2天。我知道这很简单。我已经尝试了很多次。
$sql = "SELECT column_name FROM table_name";
$query = mysqli_query($con,$sql) or die (mysqli_error($con));
while ($row = mysqli_fetch_array($query))
{
$column_name = $row['column_name'];
}
$sql2 = "UPDATE table_name SET column_name = 1 WHERE ID= '$ID'";
$query2 = mysqli_query($con, $sql2) or die (mysqli_error($con));
ID Colour column_name
1 Red 0
2 Yellow 1
答案 0 :(得分:0)
你需要你所有的column_name 0到1然后像这样使用
$sql = "SELECT ID, column_name FROM table_name";
$query = mysqli_query($con,$sql) or die (mysqli_error($con));
while ($row = mysqli_fetch_array($query))
{
if($row['column_name'] == 0) {
$sql2 = "UPDATE table_name SET column_name = 1 WHERE ID= ".$row['ID'];
$query2 = mysqli_query($con, $sql2) or die (mysqli_error($con));
}
}