-1

I want to put the result of an sqli-query into an array, but I have absolutley no idea how to do that.

In the example code are 2 results, but only one of them ends up in the array.

Can't wait to hear your ideas!

$result = runSQL("SELECT `trackingnumber` FROM `tracking` WHERE `chat_id`=$chatId");                
        while ($row = $result->fetch_assoc())  {
               $res = $row['trackingnumber']; 
               $info = array($res); 
            }
        print_r($info);  

Justin
  • 15
  • 6

1 Answers1

3

You are overwriting the variable info with each iteration. You need to append your results, e.g.

$info = [];
while ($row = $result->fetch_assoc())  {
    $info[] = $row['trackingnumber']; 
}
DarkBee
  • 16,592
  • 6
  • 46
  • 58