Forum Moderators: coopster

Message Too Old, No Replies

simple foreach not printing values ?

         

amwd07

10:27 pm on Jul 26, 2008 (gmt 0)

10+ Year Member



I need a little urgent help please with the following array
the values do not seem to be printed ?

$eachproduct = array();
$products = Db::getInstance()->ExecuteS('SELECT id_image, id_product FROM ps_image GROUP BY id_product');

foreach ($products as $key => $product) {
$productID = $eachproduct[$products['id_product']];
$imageID = $eachproduct[$products['id_image']];
print "product ID = $productID image ID = $imageID <br/>";
}

results from print below

product ID = image ID =
product ID = image ID =
product ID = image ID =
product ID = image ID =
product ID = image ID =
product ID = image ID =
product ID = image ID =

MattAU

1:40 am on Jul 27, 2008 (gmt 0)

10+ Year Member



I think you've got your arrays mixed up. You create the $eachproduct array, but don't populate it anywhere... Then you're using the $products array as if it isn't a multi-dimensional array, when it will be... Try this:

foreach ($products as $key => $product) {
$productID = $product['id_product'];
$imageID = $product['id_image'];
print "product ID = $productID image ID = $imageID <br/>";
}