smarty分页缓存处理

log.html

<table width="600" align="center" cellspacing="1" bgcolor="#CCCCCC" style="font-size:14px;font-family:Arial, Helvetica, sans-serif;">
 <tr>
   <th bgcolor="#FFFFFF">标题</th>                 
   <th bgcolor="#FFFFFF">评论/查看</th>
   <th bgcolor="#FFFFFF">发表时间</th>
 </tr>
 {foreach item=cl from=$tlist} 
  <tr>
    <td bgcolor="#FFFFFF">
     <a target="_blank" href="{$url}/logshow.php?id={$cl.blogid}&classid={$cl.logclassid}">{$cl.title}</a>
    </td>
    <td align="center" bgcolor="#FFFFFF">{$cl.commentnum}/{$cl.viewnum}</td>
    <td align="center" bgcolor="#FFFFFF">{$cl.dateline|date_format:"%Y-%m-%d %H:%M"}</td>
  </tr>
 {/foreach}
 <tr>
 <td colspan="3" align="center" bgcolor="#FFFFFF">
  {$pagebar} 
 </td>
 </tr>               
</table>

log.php

<?php
 $pagename=$_SERVER['SCRIPT_NAME'];
 include "conn.php";
 include "page.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 = true;
 $smarty->left_delimiter="{";
 $smarty->right_delimiter="}";
 $smarty->cache_lifetime=600; 
 $url="http://www.siyuroom.com";//家园地址
 $sql_num = "select count(*) from siyuroom_log";
 $pagesize=10; //每页显示条数  
 $resnum=mysql_result(mysql_query($sql_num),0);
 $pagecount=ceil($resnum/$pagesize);    //总页数
 //当前页数
 if (isset($_GET['page'])){
  $page=$_GET['page'];
 }else{
  $page=1;
 }
 if(empty($_GET['page'])){
  $page=1;
 }
 if($page>$pagecount){$page=1;}    //如果当前页大于总页数,则转为第一页
 $sql="select * from siyuroom_log order by datetime desc limit ".(($page-1)*$pagesize).",".$pagesize;
 mysql_query("set names gb2312");
 $query=mysql_query($sql);
 $tlist=array();
 $i=0;
 while($myrow = mysql_fetch_array($query)){ 
  $tlist[$i]['blogid']=$myrow['id'];
  $tlist[$i]['logclassid']=$myrow['logclassid'];
  $tlist[$i]['title']=$myrow['title'];
  $tlist[$i]['viewnum']=$myrow['hit'];
  $tlist[$i]['commentnum']=$myrow['commentnum'];
  $tlist[$i]['dateline']=$myrow['datetime']; 
  $i++;
 }
 $pagefollow="";    //页面链接参数
 $pagebar=pagelist($resnum,$pagesize,$page,$pagefollow,'条日志');   //分页函数(总记录条数,每页显示条数,当前页,链接参数)
 $smarty->assign( 'url', $url );//设置当前页面
 $smarty->assign( 'tlist', $tlist );//设置当前页面
 $smarty->assign( 'pagebar', $pagebar );//分页显示
 $smarty->display('log.html',$page);
?>

page.php

<?
 //分页函数(总记录条数,每页显示条数,当前页,链接参数,跟随翻页的内容)
 function pagelist($resnum,$pagesize,$page,$pagefollow,$mytext)
 { 
  //显示信息pagestr
  $pagestr="";
 
  //总页数pagecount
  $pagecount=ceil($resnum/$pagesize);
 
  $pagestr="共有:".$resnum.$mytext."&nbsp分页:<b>".$page."</b>/".$pagecount."&nbsp;&nbsp;";
  
  if($pagecount!=1 && $pagecount!=0){
     if($page>1){
       if($page < $pagecount){
       $pagestr=$pagestr."[<a href="?page=1".$pagefollow."">第一页</a>]";
       $pagestr=$pagestr."[<a href="?page=".($page-1).$pagefollow."">上一页</a>]";
       $pagestr=$pagestr."[<a href="?page=".($page+1).$pagefollow."">下一页</a>]";
       $pagestr=$pagestr."[<a href="?page=".$pagecount.$pagefollow."">最后一页</a>]";
       }else{
       $pagestr=$pagestr."[<a href="?page=1".$pagefollow."">第一页</a>]";
       $pagestr=$pagestr."[<a href="?page=".($page-1).$pagefollow."">上一页</a>]";
       $pagestr=$pagestr."[下一页] [最后一页]";
       }
     }else{
       $pagestr=$pagestr."[第一页] [上一页]";
       $pagestr=$pagestr."[<a href="?page=".($page+1).$pagefollow."">下一页</a>]";
       $pagestr=$pagestr."[<a href="?page=".$pagecount.$pagefollow."">最后一页</a>]";
     }
  }
  else{
     $pagestr=$pagestr."[第一页] [上一页] [下一页] [最后一页]";
  }
 
  $pagestr=$pagestr."&nbsp;&nbsp;<INPUT TYPE=text size=3 value=".$page." onmouseover='this.focus();this.select()' NAME=PGNumber> <INPUT TYPE=button id=button1 name=button1 value=GO onclick="."""."if(document.all.PGNumber.value>0 && document.all.PGNumber.value<=".$pagecount."){window.location='?page='+document.all.PGNumber.value+'".$pagefollow."'}"."""." onmouseover='this.focus()' onfocus='this.blur()'>";
  return $pagestr;
 }
?>

    A+
发布日期:2009年10月27日  所属分类:未分类

发表评论

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