码迷,mamicode.com
首页 > Web开发 > 详细

php分页查询

时间:2016-05-13 08:42:35      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

<?php
include "page.class.php";
include "db.class.php";
$db = new DB();
$name = "";
$tj = "";
if(!empty($_POST["mc"]))		//判断查询文本框是否有值
{
	$name = $_POST["mc"];
	$tj = "n={$name}";		//***分页条件
}
if(!empty($_GET["n"]))			//根据post传值判断
{
	$name = $_GET["n"];
	$tj = "name={$name}";
}
$w = " where AreaName like ‘%{$name}%‘ ";	//条件查询
?><br />
<form action="fenye.php" method="post">  <!--建立查询按钮-->
<div>	
请输入名称:
<input type="text" name="mc" 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
$sql1 = "select count(*) from chinastates ".$w;		//数据总量
$attr = $db->Query($sql1);
$total = $attr[0][0];		
$page = new Page($total,10,$tj,true);	//1,数据总量  2,每页的数据量  3,分页条件  4,true显示首页、false显示末页
$sql2 = "select * from chinastates ".$w.$page->limit;	//条件分页查询
$r = $db->Query($sql2);
foreach ($r as $v)
{
	echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td></tr>";
}
?>
</table><br />
<?php
echo $page->fpage();		//分页查询菜单
?>

  

php分页查询

标签:

原文地址:http://www.cnblogs.com/1116zsc/p/5485440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!