這篇文章主要為大家展示了“如何實現(xiàn)PHP搜索加分頁”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學習一下“如何實現(xiàn)PHP搜索加分頁”這篇文章吧。

示例代碼:
自己調(diào)試運行一次,好把它修改一次,加上自己的功能。
$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);
}
//分頁的實現(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">
標題:<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>編號</td>
 <td>標題</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 " 當前{$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>以上是“如何實現(xiàn)PHP搜索加分頁”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
                文章名稱:如何實現(xiàn)PHP搜索加分頁-創(chuàng)新互聯(lián)
                
                鏈接分享:http://www.chinadenli.net/article24/dcsoje.html
            
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、網(wǎng)站排名、動態(tài)網(wǎng)站、建站公司、企業(yè)建站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)