tpl文件内容:
<tr class="tdbg">
<td width="6%" align="center" height="25">选中</td>
<td width="6%" align="center">ID</td>
<td width="45%" align="center" >文章标题</td>
<td width="7%" align="center" >点击数</td>
<td width="13%" align="center" >文章属性</td>
<td width="23%" align="center" >操作</td>
</tr>
{{foreach from=$NewsList item=News}}
<tr class="tdbg" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#BFDFFF'">
<td height="25" align="center">
<input name="NewsID" type="checkbox" id="NewsID" value="{{$News.NewsID}}" style="border: 0px;background-color: #eeeeee;">
</td>
        <td align="center">{{$News.NewsID}}</td>
        <td>{{$News.Title}}</td>
        <td align="center">{{$News.Hits}}</td>
        <td align="center">{{$News.Hot}}</td>
        <td align="center">
     热点 推荐 审核
    <a href="Admin_NewsModify.asp?NewsID=&page=">修改</a>&nbsp;
    <a href="#" onClick="if(confirm('您真的要删除这篇文章吗?')){location.href='?Action=Del&page=&NewsID='}">删除</a>
   </td>
</tr>
{{/foreach}}php文件内容: global $smarty;
$conn = new DataBase();
$conn->sql = "select NewsID,Title,Hits,Hot from news order by NewsID desc";
$conn->execute();
while ($row = $conn->fetchAssoc())
{
$arr[] = $row;
}
//print_r($arr);
$smarty->assign("NewsList",$arr);
$smarty->display("Admin_News_List.tpl");
现在有问题如下:
一、我这样写,程序方面有没有不好的地方,比如运行速度,因为我看到过有人没有用while循环重组数组,而是直接用结果集替换。
二、{{$News.Hot}}这个字段是Bool型的数据,我想实现如下效果:如果为真则显示“热点”两个字,否则不显示。请问如何处理?非常感谢。

解决方案 »

  1.   

    1. 在$conn->execute(); 之后, 正常情况数组应该重组一次返回结果, 详细看类DataBase, 你这里的类可能没有重组
    2. {{ if($News.Hot) }}  热点 {{ /if }}
      

  2.   

    谢谢楼上的
    {{ if $News.Hot }}  热点 {{ /if }}
    {{ if( $News.Hot == 1) }}  热点 {{ /if }}
    {{ if $News.Hot == 1 }}  热点 {{ /if }}
    都可以,还有啊。$News.Hot不能跟它左边的"("符号紧挨着,不然smarty引擎会提示错误的。
    是不是啊???
      

  3.   

    都可以,还有啊。$News.Hot不能跟它左边的"("符号紧挨着,不然smarty引擎会提示错误的。 
    是不是啊???----------------------个人设置不同, 自己可以灵活运用, 我的smarty可以直接这样{{if($News.Hot)}}写,   两边粘着"("也不会报错