您的位置:首页 > 编程语言 > PHP开发

PHP分页显示和查询

2016-06-21 13:20 375 查看
<!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=" area_name 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>
<br />
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>父级代号</td>
<td>名称</td>
</tr>
<?php

//求总条数
$szong="select count(*) from crm_area".$ztj;
$azong=$db->Query($szong);
$zongshu=$azong[0][0];//总条数
//造分页对象
$page=new Page($zongshu,15);//四个参数,第二个默认25,三四个有默认值
//在SQL语句拼接分页条件
$sql="select * from crm_area ".$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[2]}</td>
</tr>";
}
?>
</table>
<div>
<?php
//返回分页信息
echo $page->fpage();
?>
</div>
</body>
</html>

  

<!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=" area_name like '%{$_POST['name']}%' ";
$name=$_POST["name"];
}
if(!empty($_GET["name"]) && $_GET["name"]!="")
{
$tj=" area_name 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>
<br />
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>父级代号</td>
<td>名称</td>
</tr>
<?php

//求总条数
$szong="select count(*) from crm_area".$ztj;
$azong=$db->Query($szong);
$zongshu=$azong[0][0];//总条数
//造分页对象
$page=new Page($zongshu,15,$posttj);//四个参数,第二个默认25,三四个有默认值
//在SQL语句拼接分页条件
$sql="select * from crm_area ".$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[2]}</td>
</tr>";
}
?>
</table>
<div>
<?php
//返回分页信息
echo $page->fpage();
?>
</div>
</body>
</html>

  

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: