php分页查询
分页查询页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php include("DBDA.class.php"); $db = new DBDA(); include "page.class.php"; $tj1 = " 1=1 ";//默认值的写入 $area = ""; if(!empty($_GET["area"]))//由于page.class.php类文件,用的是get方法 { $area = $_GET["area"]; $tj1 = " areaname like '%{$area}%' "; } ?> <h1>中国省市区</h1> <form action="1.php" method="get"> <div>地区名称:<input type="text" name="area" value="<?php echo $area; ?>" /> <input type="submit" value="查询" /></div> </form> <br /> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>地区代号</td> <td>地区名称</td> <td>父级代号</td> </tr> <?php $sall = "select count(*) from chinastates where {$tj1}";//加条件 $aall = $db->Query($sall); $page = new Page($aall[0][0],20);//如用post此处可以new Page($aall[0][0],20,"area={$area}")第三个参数可以像get方法的在地址栏里显示。
//但是由于page.class.php类文件是get方法的,如果用post显示有问题。 $sql = "select * from chinastates where {$tj1} ".$page->limit;//加条件 $arr = $db->Query($sql); foreach($arr as $v) { echo "<tr> <td>{$v[0]}</td> <td>{$v[1]}</td> <td>{$v[2]}</td> </tr>"; } ?> </table> <div><?php echo $page->fpage(); ?></div> </body> </html>