How do I take out the value of foreach and update the table?

$keyyy = null;

while ($r = mysqli_fetch_array($rs)){

    $tagg = array($r["name"]);

    foreach ($tagg as $key) {
      $keyyy = $key.",";
    }
}

the printed result is

1,2,3,4,5,

just why do I only have 5, when I update to the number table?
instead of 1, 2, 3, 4, 5,

UPDATE `blog` SET
      `tags` = "{$keyyy}"
      WHERE url = "XXX"
Jul.28,2021

you may be missing a dot
$keyyy. = $key.',';


UPDATE blog SET

  `tags` = '{$keyyy}'
  WHERE url = 'XXX'
  

print the SQL statement before executing UPDATE to see if tags has changed


what is your purpose?
$keyyy = null;

while ($r = mysqli_fetch_array ($rs)) {

)
$tagg = array($r['name']);

foreach ($tagg as $key) {
  $keyyy = $key.',';
  
  echo $keyyy ;// 
}

}

the result is what you see: 1 keyyy 2, 3, 4, 5, but it actually prints this variable five times, and each time the value is overwritten by a new one, so the last value of $meme is 5,

.

if you only need to update, once, you can change it like this: $keyyy. = $key.',';
if each needs update, then put the update statement in the loop to execute.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e890a4-f24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e890a4-f24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?