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>
<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型的数据,我想实现如下效果:如果为真则显示“热点”两个字,否则不显示。请问如何处理?非常感谢。
<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>
<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型的数据,我想实现如下效果:如果为真则显示“热点”两个字,否则不显示。请问如何处理?非常感谢。
解决方案 »
- 用表格输出数据表中的数据
- 分层做雇员管理系统,check the manual that corresponds to your MySQL server version 这是什么错误?
- 除了 include() include_once() require() require_once() 之外的文件调用外 还可以有其他调用方法吗?
- PHP中转义字符及变量无效的问题?
- 数组重新组合
- 编写PHP时,大家都用什么IDE呀!?
- PHP多个连续空格回车替换为一个,如何写更简短?
- 紧急求救,页面设置问题。急!急!急!急!急!急!急!急!
- 这一类:_FILES[] 变量的详细资料在那里可以找到?
- php留言本问题
- 如何写一个函数,既可以删除一片新闻也可以删除多篇新闻。
- 目前LAMP哪几个版本搭配起来好一点
2. {{ if($News.Hot) }} 热点 {{ /if }}
{{ if $News.Hot }} 热点 {{ /if }}
{{ if( $News.Hot == 1) }} 热点 {{ /if }}
{{ if $News.Hot == 1 }} 热点 {{ /if }}
都可以,还有啊。$News.Hot不能跟它左边的"("符号紧挨着,不然smarty引擎会提示错误的。
是不是啊???
是不是啊???----------------------个人设置不同, 自己可以灵活运用, 我的smarty可以直接这样{{if($News.Hot)}}写, 两边粘着"("也不会报错