求助,smarty循环不显示
<br />$arr=$_SESSION["mycar"];//从session中拿出二维数组<br />$smarty->assign("arr",$arr);<br />
<br /> {section name=a loop=$arr} <br /> <tr><br /> <td width="96">{$arr[a].pid}</td><br /> <td width="158">{$arr[a].name}</td><br /> <td width="154">{$arr[a].num}</td><br /> <td width="177"><a href="delete.php?id={$arr[a].pid}">删除</a></td><br /> </tr><br /> {/section}<br />
print_r(arr)有数据;
Array ( [27] => Array ( [pid] => 27 [name] => 玻璃茶几 [num] => 11 ) [26] => Array ( [pid] => 26 [name] => 布艺沙发 [num] => 6 ) [25] => Array ( [pid] => 25 [name] => [num] => 4 ) [24] => Array ( [pid] => 24 [name] => [num] => 6 ) )
但是表里只有4行框,不显示数据啊
------解决思路----------------------{section name=a loop=$arr} 将这一行后面的空格删掉应该就可以了。
------解决思路----------------------{
section name=a loop=$arr}
要求数组的下标从 0 开始
你 error_reporting(E_ALL); 就可以看到错误信息了
$smarty->assign("arr",$arr);
应写作
$smarty->assign("arr",array_values($arr));
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn