分页查询

<body>
<br />
<form action="zgdiqu.php" method="get">
<div>地区名称:<input type="text" name="name" />
<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
include("./FZL.class.php");
require("./FYL.class.php"); //引入分页类

$db = new FZL();

$tj = " 1=1 ";
if(!empty($_GET["name"]))
{
$name = $_GET["name"];
$tj = " areaname like '%{$name}%' ";
}

//求总条数
$sz = "select count(*) from chinastates where ".$tj;
$az = $db->Query($sz);
$zts = $az[0][0];

echo $zts;
//造分页类对象
$FYL = new FYL($zts,20); //构造函数 需要4个参数,后边两个参数不用写,因为从第二个参数开始都有默认值

$sql = "select * from chinastates where ".$tj.$FYL->limit;
echo $sql;

$attr = $db->Query($sql);
foreach($attr as $v)
{
echo"<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
</tr>";
}

?>
</table>
<div><?php
//调用分页信息并输出
echo $FYL->fpage();
?></div>
</body>

如何显示搜寻内容

<body>
<?php
include("./FZL.class.php");
require("./FYL.class.php"); //引入分页类

$db = new FZL();

$tj = " 1=1 ";
$name = "";
if(!empty($_GET["name"]))
{
    $name = $_GET["name"];
    $tj = " areaname like '%{$name}%' ";    
}

?>
<br />
<form action="zgdiqu.php" method="get">
   <div>地区名称:<input type="text" name="name" value="<?php echo $name;?>"/>
<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


//求总条数
$sz = "select count(*) from chinastates where ".$tj;
$az = $db->Query($sz);
$zts = $az[0][0];

echo $zts;
//造分页类对象
$FYL = new FYL($zts,20);  //构造函数 需要4个参数,后边两个参数不用写,因为从第二个参数开始都有默认值

$sql = "select * from chinastates where ".$tj.$FYL->limit;
echo $sql;

$attr = $db->Query($sql);
foreach($attr as $v)
{
    echo"<tr>
          <td>{$v[0]}</td>
          <td>{$v[1]}</td>
          <td>{$v[2]}</td>
         </tr>";
}

?>
</table>
<div><?php 
//调用分页信息并输出
echo $FYL->fpage();
?></div>
</body>

此类方式的缺陷就是刷新页面

posted @ 2016-12-27 15:27  欧元  阅读(159)  评论(0编辑  收藏  举报