I am selecting rows from the database. When I print_r it is showing 3 records, but inside my 2nd foreach it's only showing 1 record.
//get productid
$product = $database->prepare("SELECT * FROM bids,orders,products WHERE bids.bids_username=? AND NOW() > products.enddate AND orders.orders_status=0 GROUP BY bids.bids_item ORDER BY bids.bids_amount DESC");
$product->execute(array($username->username));
$productid = $product->fetchAll();
print_R($productid);
//check if order is in database
foreach($productid as $product):
$order = $database->prepare("SELECT * FROM orders WHERE orders_product=? AND orders_username=?");
$order->execute(array($product->bids_item, $username->username));
$result = $order->fetchAll();
endforeach;
//insert order
if(!$result):
$createorder = $database->prepare("INSERT INTO orders(orders_username,orders_product,orders_firstname, orders_lastname, orders_address1, orders_address2, orders_zipcode, orders_city, orders_country, orders_btcaddress, orders_status) VALUES(?,?,?,?,?,?,?,?,?,?,?)");
foreach($productid as $product):
echo $product->bids_item;
//get btc address, check it's valid, then if isset run query below
$createorder->execute(array($username->username, $product->bids_item, $username->firstname, $username->lastname, $username->address1, $username->address2, $username->zipcode, $username->city, $username->country, 'jkjkjk', 0));
return 1;
endforeach;
endif;
Whem I echo the bids_item it's only showing 1 result when it should run through all 3 and echo them all. Is there anything in my code that looks wrong?