//FETCH ID
$sql = mysqli_query($conn,"select * from XX") or die("error");
while($row = mysqli_fetch_array($sql))
{
$id = $row['id'];
}
// USE FOREACH LOOP TO DO MULTIPLE UPDATES
foreach ($id as $x ) {
$sql2 = "UPDATE XX SET XX=0 and XX='' WHERE id='$x'";
mysqli_query($conn,$sql2);
}
我尝试通过使用 mysqli_fetch_array 获取它们的 ID,然后将它们发送到 foreach 循环以在我的数据库中更新每个 ID,从而对我的数据库进行多次更新,
但是出了点问题并且没有更新,有人可以帮助我完成这个
亲爱的用户,您以错误的方式编写代码,只需修改代码即可希望您能得到答案
$sql = mysqli_query($conn,"select * from XX") or die("error");
// always check count for better debuging
if(mysqli_num_rows($sql)>0){
// create blank array
$id=array();
while($row = mysqli_fetch_array($sql))
{
// add id to array you can use array_push($id,$row['id']) also
$id[] = $row['id'];
}
// USE FOREACH LOOP TO DO MULTIPLE UPDATES
foreach ($id as $x ) {
// you have error in update query also you need to use (,) instead of and
//your query
$sql2 = "UPDATE XX SET XX=0 and XX='' WHERE id='$x'";
//my Query
$sql2 = "UPDATE XX SET XX=0, XX='' WHERE id='$x'";
mysqli_query($conn,$sql2);
}
}