smarty隔行换颜色

color.tpl

<html>
<head><title>隔行换背景颜色</title><head>
<body>
<table border="1">
<{assign var="Color" value="#ff0000"}>
<Tr>
<TD colspan="2">色彩:<{$Color}></Td>
</Tr>
<{section name=loop loop=$log}>
<{if $Color == "#ff0000"}>
<tr bgcolor="<{$Color}>">
<{assign var="Color" value="#CCCCCC"}>
<{else $Color == "#CCCCCC"}>
<tr bgcolor = "<{$Color}>">
<{assign var="Color" value="#ff0000"}>
<{/if}>
<td><{$log[loop].logid}></td>
<td><{$log[loop].title}></td>
<tr>
<{/section}>
</table>
</body>
</html>

color.php

<?php
 include "conn.php";
 require("../libs/smarty.class.php");
 $smarty = new Smarty();
 $smarty->template_dir = 'templates/'
 $smarty->compile_dir = 'templates_c/'
 $smarty->config_dir = 'configs/'
 $smarty->cache_dir = 'cache/'
 $smarty->caching = false;
 $smarty->left_delimiter="<{";
 $smarty->right_delimiter="}>";
 $sql="select id,logclassid,title from log order by datetime desc limit 0,10";
 mysql_query("set names gb2312");
 $query=mysql_query($sql);
 while($row=mysql_fetch_array($query)){
  $array[]= array("logid"=>$row["id"],"title"=>$row["title"]);
 }
 $smarty->assign("log", $array);
 $smarty->display("color.tpl");
?>
 

    A+
发布日期:2009年08月15日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: