i learn from PHP MYSQL updating multiple rows using values from an array
$array = Array();
$query = $conn->query("
SELECT P.email,P.kodeunik FROM peserta P
LEFT JOIN konfirmasi K ON K.nominal=P.kodeunik
LEFT JOIN detailbca D ON D.mutasi =P.kodeunik
where P.paid='0' AND K.paid='0' AND D.paid='0'");
while($result = $query->fetch_assoc()){
$array[] = $result;
}
$email = implode(',', array_column($array, 'email'));
$nominal1 = implode(',', array_column($array, 'kodeunik'));
echo $nominal1; // 215003,215004,215005
now i want update table if have several number from $nominal1 , in this case 3 row table will be update
$array1=$nominal1;
$sql1 = "UPDATE detailbca SET paid='1'
WHERE mutasi IN (' . implode(',', array_map('intval', $array1)) .";
$sql1 = $conn->query($sql);
this query not working, what wrong?
No need to use implode()
again .
You can do this way array_column()
on kodeunik column of $array
, then array_map()
with intval
and finaly implode()
it using ,
.
$email = "'" . implode("','", array_column($array, 'email')) . "'";
$nominal1 = implode(',', array_map('intval',array_column($array, 'kodeunik')));
$sql1 = "UPDATE detailbca SET paid='1' WHERE mutasi IN ($nominal1)";
$sql1 = $conn->query($sql);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.