search
HomeBackend DevelopmentPHP 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>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment