0
    $stmt = $db->get_products();

$products = array();
foreach($stmt as $items){
    $products = array('asin'=>$items['asin']);
}

print_r($products);

Assuming my $stmt contains 4 values from my database, my problem is that I only get the first data in my print_r, not all the data from my database. But when I echo inside the foreach it displays the expected output but when passing it to an array it only contains one value.

1 Answer 1

2

You should replace

$products = array('asin'=>$items['asin']);

with

$products[] = array('asin'=>$items['asin']);
          ^--- Missing bracket 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.