Home >Backend Development >PHP Tutorial > 求个具体的php+mysql分页-不用网上搜的
求个具体的php+mysql分页-----不要网上搜的
一、从a页点击在b页进行分页显示
二、分页显示的代码
三、有首页 上页 1 2 3 4 5 下页 末页的功能
四、翻页后能正常显示内容就是点击上页下页能正常显示数据库的数据(a页传来的参数不丢失),
class page{<br> private $_page_num;//总页数<br> private $_page_size=10;//每页条数<br> private $_page_url;//url链接<br> private $_limit;//limit1<br> private $_page_total;//总分页数<br> private $_page;//分页所传分页值<br> private $_list_size=10;//这为第二种分页方法显示条数<br> private $_page_sort=3;//分页两边距离<br> public function __construct($_total,$_pagesize,$_list_size){<br> $this->_page_size=$_pagesize;<br> $this->_page_total=$_total;<br> $this->_list_size = $_list_size;<br> $this->_page_num = round($this->_page_total/$this->_page_size);<br> $this->_page=$this->getnum();<br> $this->_limit="limit".$this->_page*$this->_page_size.",".$this->_page_total=$_total;<br> $this->_page_url=$this->seturl();<br> }<br> /**<br> * 获取当前页数<br> * Enter description here ...<br> */<br> private function getnum(){<br> if(isset($_GET['page'])){<br> if(is_numeric($_GET['page'])){<br> if($_GET['page']>0){<br> if(ceil($_GET['page'])>=1 && ceil($_GET['page'])_page_num){<br> return ceil($_GET['page']);<br> }elseif(ceil($_GET['page'])>$this->_page_num){<br> return $this->_page_num;<br> }<br> }else{<br> return 1;<br> }<br> }else{<br> return 1;<br> }<br> }else{<br> return 1;<br> }<br> }<br> /**<br> * 转换链接<br> * Enter description here ...<br> */<br> private function seturl(){<br> $_url=$_SERVER['REQUEST_URI'];//获取请求地址<br> $_par=parse_url($_url);//解析url<br> if(isset($_par['query'])){//判断是否存在aa=bb这种格式<br> $_url=parse_str($_par['query'],$_query);//重构url<br> unset($_query['page']);<br> $_url=$_par['path'].'?'.http_build_query($_query);<br> }else{<br> $_url=$_url.'?';<br> }<br> return $_url;<br> }<br> <br> public function limit(){<br> return $this->_limit;<br> }<br> <br> public function pagenum(){<br> return $this->_page_num;<br> }<br> <br> /*<br> public function page(){<br> return $this->_page;<br> }<br> public function pageurl(){<br> return $this->_page_url;<br> }<br> */<br> <br> private function first(){<br> return "<a>_page_url."&page=1>首页</a>";<br> }<br> private function end(){<br> return "<a>_page_url."&page=".$this->_page_num.">尾页</a>";<br> }<br> private function prev(){<br> if($this->_page>1){<br> return "<a>_page_url."&page=".($this->_page-1).">上一页</a>";<br> }else{<br> return '上一页';<br> }<br> }<br> public function next(){<br> if($this->_page_page_num){<br> return "<a>_page_url."&page=".($this->_page+1).">下一页</a>";<br> }else{<br> return '下一页';<br> }<br> }<br> private function pagelist_1(){<br> $_page='';<br> for($i=1;$i_page_num;$i++){<br> $_page.="<a>_page_url."&page=".$i.">".$i."</a>";<br> }<br> return $_page;<br> }<br> private function pagelist_2(){<br> $_page=''; <div class="clear"> </div>