这个mysql更新:
function updateOrder($id_array){
$count = 1;
foreach ($id_array as $id){
$update = mysqli_query($this->connect,"UPDATE `table_name` SET `order_id` = $count WHERE id = $id");
$count ++;
}
return true;
}
我将改为PDO,这是我的写代码,但可以工作 但这没有反映在db
中function update($id_array,$_table){
$query = "UPDATE `table_name` SET `order_id` = ? WHERE id = ?";
$stmt = $this->conn->prepare($query);
$count = 1;
foreach ($id_array as $id) {
$stmt->execute(array(':$count' => $count, ':id' => $id));
$count ++;
}
return true;
}
呼叫功能:$idArray = explode(",",$_POST['ids']);<br>
$db->update($idArray);
答案 0 :(得分:4)
使用:
$stmt->execute(array(':count' => $count, ':id' => $id));
而不是
$stmt->execute(array(':$count' => $count, ':id' => $id));
:$ count 到:计数