使用PHP和 Smarty写东西的时候,为什么无法正确的循环?数据库bloginfo表中有 ID,blogname,blogurl,display....等等字段。。//index.php
<?php
require "core.php"; $sql = mysql_query("select * from bloginfo");
$maxblog = mysql_fetch_array($sql); $tpl->assign("maxblog", $maxblog);
$tpl->display("index.html");
?>
//index.html {section name=mg loop=$maxblog}
<td width="20%"><a href="{$maxblog[mg].blogurl}">{$maxblog[mg].blogname}</a></td>
{/section}
<?php
require "core.php"; $sql = mysql_query("select * from bloginfo");
$maxblog = mysql_fetch_array($sql); $tpl->assign("maxblog", $maxblog);
$tpl->display("index.html");
?>
//index.html {section name=mg loop=$maxblog}
<td width="20%"><a href="{$maxblog[mg].blogurl}">{$maxblog[mg].blogname}</a></td>
{/section}
所以 从你的代码看 你传人html的变量maxblog就一个 你怎么循环??2.解决办法:
在php里面
$maxblog = array();
while ($row = mysql_fetch_array($sql)) {
$maxblog[] = $row
}