這篇文章主要為大家展示了“如何實(shí)現(xiàn)PHP搜索加分頁(yè)”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何實(shí)現(xiàn)PHP搜索加分頁(yè)”這篇文章吧。
示例代碼:
自己調(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); } //分頁(yè)的實(shí)現(xiàn)原理 //1.獲取數(shù)據(jù)表中總記錄數(shù) $sql="select count(*) from news $where "; $result=mysql_query($sql); $totalnum=mysql_num_rows($result); //每頁(yè)顯示條數(shù) $pagesize=5; //總共有幾頁(yè) $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); ?>
編號(hào) | 標(biāo)題 | 關(guān)鍵字 | 作者 | 日期 | 內(nèi)容 |
首頁(yè) "; echo "上一頁(yè)"; echo "下一頁(yè)"; echo " 尾頁(yè) "; ?> |
以上是“如何實(shí)現(xiàn)PHP搜索加分頁(yè)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!