php 分页查询

get方法

<!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>
<h1>主页面</h1>
<?php
include("dbda.class.php");
$db=new dbda();

include("page.class.php");

$tj=" 1=1 ";

$name="";

if(!empty($_GET["name"]) && $_GET["name"]!="")
{
    $tj=" areaname like '%{$_GET['name']}%' ";    
    $name=$_GET["name"];
}
$ztj=" where {$tj}";
?>
<form action="fenye.php" method="get">
<div>名称:<input type="text" name="name" value="<?php echo $name; ?>" /><input type="submit" 
 value="查询" /></div>
 </form>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
    <td>代号</td>
    <td>区域名称</td>
    <td>父级代号</td>
</tr>
<?php


//求总条数
$szong="select count(*) from chinastates".$ztj;
$azong=$db->Query($szong);
$zongshu=$azong[0][0];//总条数

//造分页对象
$page=new Page($zongshu,20);


//在    SQL语句拼接分页条件
$sql="select * from chinastates ".$ztj.$page->limit;
echo $sql;
$attr=$db->Query($sql);

foreach($attr as $v)
{
    echo "<tr>
        <td>{$v[0]}</td>
        <td>{$v[1]}</td>
        <td>{$v[3]}</td>
        </tr>";    
}
?>
</table>
<div>
<?php
//返回分页信息
echo $page->fpage();
?>
</div>
</body>
</html>
View Code

post方法

<!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>
<h1>主页面</h1>
<?php
include("dbda.class.php");
$db=new dbda();

include("page.class.php");

$tj=" 1=1 ";

$name="";

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

$ztj=" where {$tj}";

$posttj="name={$name}";

?>
<form action="fenyepost.php" method="post">
<div>名称:<input type="text" name="name" value="<?php echo $name; ?>" /><input type="submit" 
 value="查询" /></div>
 </form>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
    <td>代号</td>
    <td>区域名称</td>
    <td>父级代号</td>
</tr>
<?php


//求总条数
$szong="select count(*) from chinastates".$ztj;
$azong=$db->Query($szong);
$zongshu=$azong[0][0];//总条数

//造分页对象
$page=new Page($zongshu,20,$posttj);


//在    SQL语句拼接分页条件
$sql="select * from chinastates ".$ztj.$page->limit;
echo $sql;
$attr=$db->Query($sql);

foreach($attr as $v)
{
    echo "<tr>
        <td>{$v[0]}</td>
        <td>{$v[1]}</td>
        <td>{$v[3]}</td>
        </tr>";    
}
?>
</table>
<div>
<?php
//返回分页信息
echo $page->fpage();
?>
</div>
</body>
</html>
View Code

 

posted @ 2016-06-19 17:57  哔哩哔哩干杯  阅读(146)  评论(0编辑  收藏  举报