开发者

Smarty PHP/template output problem

I have problem outputing this to page..

for ( $i = 0; $mainarray[$i] != ''; $i++ ){ 
$query =  mysql_query("SELECT开发者_开发技巧 ... FROM ... WHERE id=$i") or die(mysql_error());
while($tmp = mysql_fetch_assoc($query))
{
    $something[] = $tmp;
}
$smarty->assign('stuff'.$i, $something); 
  }

I could manualy do it like

{section name=i loop=$stuff1}
.....
{/section}
{section name=i loop=$stuff2}
.....
{/section}

but thats not really nice way.


How about just put your "stuff" into an array?

$stuff = arrray();
for ( $i = 0; $mainarray[$i] != ''; $i++ ){ 
    $query =  mysql_query("SELECT ... FROM ... WHERE id=$i") or die(mysql_error());
    while($tmp = mysql_fetch_assoc($query))
    {
        $something[] = $tmp;
    }
    $stuff[] = $something;
}

$smarty->assign('stuff', $stuff);

Then you can just loop over stuff in the template.


Looks like you might want to use a multi-dimensional array in your php code and a nested loop in smarty.

It's been awhile since I've worked with php/smarty, so this syntax may not be correct.

$stuff = array();
foreach ($mainarray as $i) {
    $query =  mysql_query("SELECT ... FROM ... WHERE id=$i") or die(mysql_error());
    $something = array();
    while($tmp = mysql_fetch_assoc($query)) {
        $something[] = $something;
    }
    $stuff[] = $something;
}
$smarty->assign('stuff', $stuff);

In smarty you would need a nested loop. I would probably butcher the smarty syntax, but this looks like a similar issue: http://www.smarty.net/forums/viewtopic.php?t=14552&highlight=nested+section

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜