最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

實(shí)現(xiàn)PHP搜索加分頁

 更新時(shí)間:2016年10月12日 14:35:38   作者:phpmaster  
本文實(shí)現(xiàn)PHP搜索加分頁,解決了大量數(shù)量瀏覽的分頁問題,力求讓看完這篇文章的朋友在看完以后對(duì)于分頁顯示的原理和實(shí)現(xiàn)方法有所了解。

分頁顯示是瀏覽大量數(shù)據(jù)的一種方法。對(duì)于初學(xué)者來說常常對(duì)這個(gè)問題摸不著頭緒,因此特地撰寫此文對(duì)這個(gè)問題進(jìn)行詳細(xì)的講解,力求讓看完這篇文章的朋友在看完以后對(duì)于分頁顯示的原理和實(shí)現(xiàn)方法有所了解。

所有示例代碼均使用php編寫。

所謂分頁顯示,也就是將數(shù)據(jù)庫中的結(jié)果集人為的分成一段一段的來顯示。

請(qǐng)?jiān)敿?xì)閱讀以下代碼,自己調(diào)試運(yùn)行一次,最好把它修改一次,加上自己的功能。

$wherelist=array();
$urlist=array();
if(!empty($_GET['title']))
{
$wherelist[]=" title like '%".$_GET['title']."%'";
$urllist[]="title=".$_GET['title'];
 
}
if(!empty($_GET['keywords']))
{
$wherelist[]=" keywords like '%".$_GET['keywords']."%'";
$urllist[]="keywords=".$_GET['keywords'];
}if(!empty($_GET['author']))
{
$wherelist[]=" author like '%".$_GET['author']."%'";
$urllist[]="author=".$_GET['author'];
}
$where="";
if(count($wherelist)>0)
{
$where=" where ".implode(' and ',$wherelist);
$url='&'.implode('&',$urllist);
}
//分頁的實(shí)現(xiàn)原理
//1.獲取數(shù)據(jù)表中總記錄數(shù)
$sql="select count(*) from news $where ";
$result=mysql_query($sql);
$totalnum=mysql_num_rows($result);
//每頁顯示條數(shù)
$pagesize=5;
//總共有幾頁
$maxpage=ceil($totalnum/$pagesize);
$page=isset($_GET['page'])?$_GET['page']:1;
if($page <1)
{
$page=1;
}
if($page>$maxpage)
{
$page=$maxpage;
}
$limit=" limit ".($page-1)*$pagesize.",$pagesize";
$sql1="select * from news {$where} {$limit}";
 
//$sql1="select * from news {$where} {$limit}";
$res=mysql_query($sql1);
 
?>
<form action="searchpage.php" method="get">
標(biāo)題:<input type="text" name="title" value="<?php echo $_GET['title']?>" size="8">
關(guān)鍵字<input type="text" name="keywords" value="<?php echo $_GET['keywords']?>" size="8">
作者:<input type="text" name="author" value="<?php echo $_GET['author']?>" size="8">
 <input type="button" value="查看全部" onclick="window.location='searchpage.php'">
 <input type="submit" value="搜索">
</form>
 
<table border="1" width="1000" align="center">
 <tr>
 <td>編號(hào)</td>
 <td>標(biāo)題</td>
 <td>關(guān)鍵字</td>
 <td>作者</td>
 <td>日期</td>
 <td>內(nèi)容</td>
 </tr>
<?php while($row= mysql_fetch_assoc($res)){?>
<tr>
 <td><?php echo $row['id'] ?></td>
 <td><?php echo $row['title'] ?></td>
 <td><?php echo $row['keywords'] ?></td>
 <td><?php echo $row['author'] ?></td>
 <td><?php echo date("Y-m-d H:i:s",$row['addtime']) ?></td>
 <td><?php echo $row['content'] ?></td>
 </tr>
<?php }?>
<tr>
 <td colspan="6">
<?php
 echo " 當(dāng)前{$page}/{$maxpage}頁 共{$totalnum}條";
echo " <a href='searchpage.php?page=1{$url}'>首頁</a> ";
echo "<a href='searchpage.php?page=".($page-1)."{$url}'>上一頁</a>";
echo "<a href='searchpage.php?page=".($page+1)."{$url}'>下一頁</a>";
echo " <a href='searchpage.php?page={$maxpage}{$url}'>尾頁</a> ";
 
?>
</td>
 </tr>
</table>

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

荔波县| 苍南县| 介休市| 黄平县| 金秀| 泾川县| 岳西县| 勃利县| 抚宁县| 梁平县| 区。| 尚志市| 扎赉特旗| 英德市| 罗平县| 城市| 赫章县| 无为县| 西平县| 深圳市| 水富县| 搜索| 南宁市| 赤城县| 新余市| 常山县| 保定市| 兴国县| 鄂伦春自治旗| 岳池县| 乌苏市| 永昌县| 杭锦后旗| 开远市| 灵台县| 巫溪县| 五华县| 永修县| 星子县| 忻州市| 广平县|