I want to combine the values I pulled from the database with foreach and assign them to a single variable. but I get an error output even though I think I did it without any problems.
(I am changing the table names for security reasons.)
<?php
// example user
$user_id= "1";
$query = $db->query("SELECT tmp.* FROM (SELECT * FROM `statistics_tables`WHERE `user`='".$user_id."' ORDER BY id DESC LIMIT 20 ) tmp ORDER BY tmp.id ASC;");
foreach($query as $row) {
$download .= $row["download"].',';
}
echo $download;
?>
error in picture
$download .= $row["download"].',';
seems to be happening on the line
CodePudding user response:
Try:
$download = [];
foreach($query as $row) {
$download[] = $row["download"];
}
echo implode(',', $download);