I have been stuck with this for a good while... And I can´t find the way of doing what I want. Heres is my code on my "module.php".
$libroarray = array(306,303,302,307);
foreach ($libroarray as $librorow)
{
$sql = 'SELECT * FROM '._DB_PREFIX_.'image WHERE `id_product` = '.$librorow;
$results = Db::getInstance()->ExecuteS($sql) ;
foreach ($results as $row)
{
$var = $row['id_image'].' ---- '.$row['id_product'].'<br />';
}
}
$this->smarty->assign('libros', $var);
return $this->display(__FILE__, 'module.tpl');
And I have this on my "module.tpl"
{foreach $libros as $item}
{$item}
{/foreach}
My problem is that it only displays the last result of "$var"
256 ---- 307
I tried everything I know... no success!!... I will never understand how to work with arrays. I can´t work them out... I know it only needs a little touch to work, but I simply can´t figure it out
Pleaseee... can anybody help?
$var
is a string not an array... use $var[]
$libroarray = array(306,303,302,307);
$var = array();
foreach ($libroarray as $librorow)
{
$sql = 'SELECT * FROM '._DB_PREFIX_.'image WHERE `id_product` = '.$librorow;
$results = Db::getInstance()->ExecuteS($sql) ;
foreach ($results as $row)
{
$var[] = $row['id_image'].' ---- '.$row['id_product'].'<br />';
}
}
$this->smarty->assign('libros', $var);
return $this->display(__FILE__, 'module.tpl');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.