How to concatenate values within a for in a variable?

0

That is, what I want to do is the following

 //tengo esta variable 
 $mivariable = '';
 $new_data = array(1,3);
 //y tengo este for
 foreach($new_data as $id){
    $stmt = $this->db->prepare('SELECT * FROM  carrito WHERE id_carrito = :id');
    $stmt->bindParam(':id',$id,\PDO::PARAM_INT);
    $stmt->execute();
    $response = $stmt->fetch();
    $mivariable .= $response['link'];

}

return $mivariable;

What I'm trying to do is make each value that it queries through the cycle to concatenate it to the mivariable variable, and what it does up to now is just take the last value, that is, the value of the last route query.

How do I do so that every time I go through the array and fence and check the value, that concatenates it to the $ mivariable variable?

    
asked by Jhon Dember Murillo Mendez 12.07.2018 в 16:24
source

0 answers