在网上学习一个小项目中有一段混编代码,如下
:<table border="1" width="500px">
<tr bgcolor="silver"><td>投票项</td><td>描述</td><td>票数</td><td><a href="#">投票</a></td></tr>
<?php foreach ($this->items as $item) {?> <tr><td><?=$item['name']?></td><td><?=$item['description']?></td><td><?=$item['vote_count']?></td><td><a href="#">投票</a></td></tr>
<?php }?>
</table>运行之后 html页面无数据显示。经过我的测试 ,$this->items 里面是存在数据的。
所以应该是php混编写法的问题,
谁懂的,帮我把错误指出一下。非常感谢
:<table border="1" width="500px">
<tr bgcolor="silver"><td>投票项</td><td>描述</td><td>票数</td><td><a href="#">投票</a></td></tr>
<?php foreach ($this->items as $item) {?> <tr><td><?=$item['name']?></td><td><?=$item['description']?></td><td><?=$item['vote_count']?></td><td><a href="#">投票</a></td></tr>
<?php }?>
</table>运行之后 html页面无数据显示。经过我的测试 ,$this->items 里面是存在数据的。
所以应该是php混编写法的问题,
谁懂的,帮我把错误指出一下。非常感谢
<tr bgcolor="silver">
<td>投票项</td>
<td>描述</td>
<td>票数</td>
<td><a href="#">投票</a></td>
</tr>
<?php foreach ($this->items as $item) {?>
<tr>
<td><?php $item['name']?></td>
<td><?php $item['description']?></td>
<td><?php $item['vote_count']?></td>
<td><a href="#">投票</a></td>
</tr>
<?php }?>
</table>
试一下这个?如果不能用,你把这个打印出来的值我看看
那只能理解为$this->items不是一个数组。
print_r($this->items);看看
那么就把<?=$item['name']?></td><td><?=$item['description']?></td><td><?=$item['vote_count']?>
改成<?php $item['name']?>~~~~~
<tr bgcolor="silver"><td>投票项</td><td>描述</td><td>票数</td><td><a href="#">投票</a></td></tr>
<?php foreach ($this->items as $item) {?>
<tr><td><?php echo $item['name']?></td><td><?php echo $item['description']?></td><td><?php echo $item['vote_count']?></td><td><a href="#">投票</a></td></tr>
<?php }?>
</table>