The day before yesterday, I wrote a paging control for PHP that I learned because of project requirements.

Source: Internet
Author: User
The day before yesterday, I wrote a paging control for my PHP project, asking me to teach me how to learn the PHP amount the day before yesterday. NET, there is no way to meet the requirements of new projects. I started learning with my head, wrote a paging control stuff, and posted it to the experts for instructions. how to call it, you don't have to say that...

 "; If (intval ($ indexDisplay) <= 0) $ indexDisplay = 0; if (intval ($ pageSize) <= 0) $ pageSize = 20; if (intval ($ ItemCount) <= 0) $ ItemCount = 0; if (intval ($ pageIndex) <= 0) $ pageIndex = 0; // calculate the total number of pages. $ pageCount = $ ItemCount % $ pageSize = 0? $ ItemCount/$ pageSize :( int) ($ ItemCount/$ pageSize) + 1; if ($ indexDisplay> $ pageCount) $ indexDisplay = $ pageCount; if ($ indexDisplay <= 0) {$ pageview = $ pageview. "homepage previous page Next Page Last Page

";} Else {// Generate the url and be compatible with the url $ url with other parameter lists = 'http ://'. $ _ SERVER ['http _ host']. $ _ SERVER ['request _ URI ']. "? "; // Url address without parameters $ urlparams = $ _ SERVER ['query _ string']; // list of URL address parameters, here we need to convert it into an array $ url = $ url. $ this-> SplitStrForArray ($ urlparams ). $ this-> showurl. "="; // The url obtained here is a complete url except pageindex that can be used on the href of the page if ($ pageIndex <= 0) // if the first page is selected, the homepage and the previous page are dimmed {$ pageview ="

Homepage previous page ";} else {$ beforeIndex = $ pageIndex-1; $ beforeUrl = $ url. $ beforeIndex; $ pageview = $ pageview ."

Homepage previous page ";}for ($ I = 0; $ I <$ indexDisplay; $ I ++) {// add a focus hobver if ($ I ==$ pageIndex) to determine the number of pages in the current constituency {$ pageview = $ pageview. "". ($ I + 1 ). "";} else {$ pageview = $ pageview. "". ($ I + 1 ). "" ;}} if ($ pageIndex = $ pageCount-1) // if the first page is selected, the home page and previous page become gray {$ pageview = $ pageview. "Last page of Next page

";} Else {$ nextIndex = $ pageIndex + 1; $ nextHref = $ url. $ nextIndex; $ lastIndex = $ pageCount-1; $ lastHref = $ url. $ lastIndex; $ pageview = $ pageview. "Last page of Next page

";}} Return $ pageview;}/*** process the url and remove the pageindex = parameter of the page, returns the * @ param string original string */function SplitStrForArray ($ sourceStr) {if ($ sourceStr = "") return "; $ strarry = explode ("&", $ sourceStr); $ newstr = ""; foreach ($ strarry as $ key) {if (explode ("=", $ key) [0]! = $ This-> showurl) {$ newstr = $ newstr. $ key. "&" ;}}/* if ($ newstr! = "") {$ Newstr = substr ($ newstr, 0, strlen ($ newstr)-1) ;}*/return $ newstr ;}}?>


Reply to discussion (solution)

Good. Come on!

Php provides
Parse_str is used to convert url parameter strings into arrays.
Http_build_query: Creates a url parameter string from an array.

Php provides
$ _ REQUEST array, no need to convert from $ _ SERVER ['query _ string'] STRING

You only need to delete pageindex.
Unset ($ _ REQUEST ['pageindex']);
Then
$ Url = http_build_query ($ _ REQUEST );
You can.

Thank you, everyone upstairs. I don't know much about it. I have taken some detours. I will find the materials and study them carefully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.