批量更新数据

$data = request()->param('id');
var_dump($data);
exit;
$update_info = array();
foreach ($data as $key => $value) {
$sql = 'Update cdr SET status = CASE id ';
foreach ($value['data'] as $value_key => $value_value) {
$sql .= ' WHEN ' . $value_value['id'] . ' THEN ' . '1';
}
$sql .= ' END WHERE id IN (';
$sql1 = '';
foreach ($value['data'] as $value_key => $value_value) {
if ($value_value == end($value['data'])) {
$sql1 .= $value_value['id'];
} else {
$sql1 .= $value_value['id'] . ',';
}
}
$sql_end = $sql . $sql1 . ');';
db('cdr')->execute($sql_end);
posted @ 2020-11-20 09:16  终究是乌云遮了天  阅读(125)  评论(0编辑  收藏  举报