在Smarty中显示子查询结果ADODB


Display sub query result ADODB in Smarty

我在PHP文件中进行了2次查询。第二个取决于第一个,我想在我的Smarty模板中显示结果。

然而,它并没有显示出好的结果。下面是代码:

首先,查询:

$sql            = "SELECT * FROM albums order by id ASC";
$rs             = $conn->execute($sql);
$galeries       = $rs->getrows();
foreach ( $galeries as $galerie ) {
    $sqlgal = "SELECT id, filename, id_album FROM pictures where id_album = ".$galerie['id']." order by id ASC limit 0,1 ";
    echo $sqlgal;
    $rsgal = $conn->execute($sqlgal);
    $picture1 = $rsgal->getrows();
}

和我将结果赋值给变量:

$oSmarty->assign('galeries', $galeries);
$oSmarty->assign('pictures', $picture1);

现在在我的模板中:

{section name=i loop=$galeries}
<div class="item">
    <div class="well">
    <a href="/galerie/{$galeries[i].id}/{$galeries[i].title|clean}.html" class="thumbnail"><img src="/photos/{$galeries[i].filename}/{$pictures[i].filename}" class="img-responsivetotal"></a>
    </div>
</div>
{/section}    

我有关于画廊的信息,但图片文件名没有出现。怎么了?我在ADODB中找不到任何关于子查询的信息

关于图片的php代码中的逻辑似乎是错误的:您循环遍历每个图库:

foreach ( $galeries as $galerie )

,并且在每个循环中都将数据赋值给$picture1,销毁前一个循环中的所有数据:

$picture1 = $rsgal->getrows();

所以,最后,$pictures只包含最后一个图库中的图片。我猜你忘记自动增加数组了:

$picture1[] = $rsgal->getrows();