Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

About combining multiple incoming variables with PHP

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$download .= $row["download"].’,’;

seems to be happening on the line

>Solution :

Try:

$download = [];

foreach($query as $row) {

    $download[] = $row["download"];

}

echo implode(',', $download);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading