Smarty 循环 section

<div id="content">
	 <div id="statistics">共{$page_count}页   {$art_count}篇文章  每页{$page_size}篇
	  {section name=pagelink start=1 loop=$page_count+1 step=1}
          <a href="index.php?pageid={$smarty.section.pagelink.index}">{$smarty.section.pagelink.index}</a>
      {/section} 
	</div>
        {section name=article loop=$show}
		<div class="post">
			<h1 class="title"><font color="red">{$show[article].id}</font>&nbsp;&nbsp;{$show[article].title}</h1>
			<div class="entry">
			{$show[article].content}
            </div>
			<div class="meta">
				<p class="links"><a href="#" class="more">分类</a> <b>|</b> <a href="#" class="comments">评论</a></p>
			</div>
		</div>
		{/section}
    </div>


$db->connect();
 $art_count_rs=$db->query("select * from articles");
 $art_count=$db->num_rows($art_count_rs);
 $page_size="5";
 $page_count=ceil($art_count/$page_size);

 $pageid=$_GET['pageid']?$_GET['pageid']:1;
 $endid=($pageid-1)*$page_size+$page_size;
 $beginid=($pageid-1)*$page_size;
 
 $sql="select *from articles ORDER by id DESC limit $beginid,$endid";
 $rs = $db->query($sql);
	while($info = $db->fetch_array($rs)){
     	 $article[]=$info;
	}
	$rows=$db->num_rows($rs);

 $db->close();

$tpl=NEW Smarty;
$tpl->assign("art_count",$art_count);
$tpl->assign("page_size",$page_size);
$tpl->assign("page_count",$page_count);
$tpl->assign("username",$username);
$tpl->assign('show',$article);
$tpl->assign('count',$rows);
$tpl->display('index.html');

你可能感兴趣的:(html,sql,PHP)