php smarty查询分页
main.php
<?php include("../init.inc.php"); include("../dbda.php"); $db=new DBDA(); include("../page.class.php"); //造查询条件 $tj=" 1=1 ";//代表名称的 $tj2=" 1=1 ";//代表科目的 if(!empty($_GET["name"])) { $tj=" name like '%{$_GET['name']}%' "; } if(!empty($_GET["kemu"])) { $tj2=" kemu = '{$_GET['kemu']}'"; } $ftj=" where".$tj." and ".$tj2; //查总数 $szong="select count(*) from timu".$ftj; $total=$db->StrQuery($szong); $page=new Page($total,1);//(总条数,每页条数,查询条件,从第一页开始); //查数据 $stimu="select * from timu ".$ftj.$page->limit;//拼上$page里面的limit属性 $timu=$db->Query($stimu); //显示分页信息 $fpage=$page->fpage(); foreach($timu as $k=>$v) { //处理正确答案名称 $sxuanxiang="select name from xuanxiang where timu={$v[0]} and xuanxiang='{$v[2]}'"; $timu[$k][2]=$db->StrQuery($sxuanxiang); //处理科目名称 $skemu="select name from kemu where code='{$v[3]}'"; $timu[$k][3]=$db->StrQuery($skemu); //处理难度名称 $snandu="select name from nandu where code='{$v[4]}'"; $timu[$k][4]=$db->StrQuery($snandu); //处理类型名称 $sleixing="select name from leixing where code='{$v[5]}'"; $timu[$k][5]=$db->StrQuery($sleixing); } //查科目 $xkemu="select * from kemu"; $kemu=$db->Query($xkemu); $smarty->assign("kemu",$kemu); $smarty->assign("timu",$timu); $smarty->assign("fpage",$fpage); $smarty->display("main.html");
main.html
<style type="text/css"> .a { padding-left:150px; padding-top:30px; } .but { padding-left:1100px; padding-top:30px; } .page { padding-left:400px; padding-top:30px; } .cha { padding-left:700px; padding-top:50px; } </style> </head> <body> <form action="main.php" method="get"> <div class="cha">题目名称: <input type="text" name="name" /> 所属科目: <select name="kemu"> <{foreach $kemu as $v}> <option value="<{$v[0]}>"><{$v[1]}></option> <{/foreach}> </select> <input type="submit" value="查询" /> </div> </form> <div class="a"> <table width="1000px" border="1" cellpadding="0" cellspacing="0"> <tr height="30px" align="center" style="font-weight:bold" > <td>题目名称</td> <td>答案</td> <td>科目</td> <td>难度</td> <td>类型</td> <td>操作</td> </tr> <{foreach $timu as $v}> <tr height="25px" align="center" > <td><{$v[1]|truncate:5}></td> <td><{$v[2]}></td> <td><{$v[3]}></td> <td><{$v[4]}></td> <td><{$v[5]}></td> <td><a href="update.php?code=<{$v[0]}>">修改</a> <a href="delete.php?code=<{$v[0]}>">删除</a> <a href="">查看详情</a></td> </tr> <{/foreach}> </table> </div><br /> <div class="page"><{$fpage}></div> <div class="but"><a href="add.php">添加数据</a></div>