日期:2014-05-16 浏览次数:20543 次
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
$sql="SELECT count(*) from khxx";
$res=mysql_query($sql);
$maxrows=mysql_result($res,0,0);
$maxpages=ceil($maxrows/$pagesize);
if($page>$maxpages){
$page=$maxpages;}
if($page<1){
$page=1;}
$limit=" limit ".(($page-1)*$pagesize).",{$pagesize}";
if (!empty($_GET[keys])) {
$keys=$_GET['keys'];
$ww="`dates` like '%".$keys."%' or `area` like '%".$keys."%' ;
$wh="where {$ww}";
}
<form action="khall.php" method="get">
<input class="inp" type="text" name="keys"/ >
<input class="sub" type="submit" value="查询"/>
</form>
</tr>
<tr>
<?php echo "当前{$page}/{$maxpages}页 共计{$maxrows}条";
echo "<a href='khall.php?page=1'>首页</a>";
echo "<a href='khall.php?page=".($page-1)."'>上一页</a>";
echo "<a href='khall.php?page=".($page+1)."'>下一页</a>";
echo "<a href='khall.php?page={$maxpages}'>末页</a>";
?>
</tr>
<?php
$sql="SELECT * FROM `khxx` {$wh} order by id desc {$limit}";
$query=mysql_query($sql);
while ($rs=mysql_fetch_array($query)){
?>
<?php
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=20;
if (!empty($_GET[keys])) {
$keys=$_GET['keys'];
$ww="`dates` like '%".$keys."%' or `area` like '%".$keys."%' ";
$wh="where {$ww}";
}else{
$wh = ""
}
$sql="SELECT count(*) from khxx ".$wh; // 计算总数时加入搜索条件
$res=mysql_query($sql);
$maxrows=mysql_result($res,0,0);
$maxpages=ceil($maxrows/$pagesize);
if($page>$maxpages){
$page=$maxpages;}
if($page<1){
$page=1;}
$limit=" limit ".(($page-1)*$pagesize).",{$pagesize}";
// 查询当前页记录
$sql="SELECT * FROM `khxx` {$wh} order by id desc {$limit}";
$query=mysql_query($sql);
while ($rs=mysql_fetch_array($query)){
?>