0

I am working on the following snippet. How can I load all affected rows into $items array?

As you can see I am able to fetch each binded cell like $pid and $psku but I need to load them to $items

$items =[];
$stmt = $conn -> prepare("SELECT `pid`,`psku` FROM `appolo` ORDER BY `pid` ASC LIMIT 24");

$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($pid, $psku);

while ($stmt -> fetch()) {
    echo $pid;
    echo $psku;
}
$stmt->free_result(); 

echo json_encode($items);
halfer
  • 19,824
  • 17
  • 99
  • 186
Mona Coder
  • 6,212
  • 18
  • 66
  • 128

1 Answers1

1

It's pretty simple, just build an array of the variables and add to an array:

while ($stmt -> fetch()) {
    $items[] = array($pid, $psku);
}

To get an associative array:

    $items[] = compact('pid', 'psku');
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87