PHP Write content Paging source analysis

Source: Internet
Author: User
Tags php code php write query

The so-called content pagination, is based on your own set of labels, the longer content according to the label you set to page, this article covers two places, one is the acquisition of the address, the Internet has many such paging tutorials, but the address is fixed, if the page has comments page and the article ID call over, it will be very troublesome, In this paper, the idea of paging principle (http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/2009/0416/807.html) in PHP100 video tutorial is adopted. There are not clear children's shoes can look at this tutorial, while using some content processing functions as well as the knowledge of the array, I wrote this article for the first time, the expression is not clear also please forgive me

First look at the effect of the picture:

For more of these paging effects, there are many of these styles in the Php100 forum, where you share the CSS style code in the picture:

Css:

 
 
  1. Div.digg {padding-right:3px; padding-left:3px; padding-bottom:3px; margin:3px; padding-top:3px; Text-align:center}
  2. Div.digg A {border-right: #aaaadd 1px solid; padding-right:5px; Border-top: #aaaadd 1px solid; padding-left:5px; padding-bottom:2px; margin:2px; Border-left: #aaaadd 1px solid; COLOR: #000099; padding-top:2px; Border-bottom: #aaaadd 1px solid; Text-decoration:none}
  3. Div.digg a:hover {border-right: #000099 1px solid; Border-top: #000099 1px solid; Border-left: #000099 1px solid; COLOR: #000; Border-bottom: #000099 1px solid}
  4. Div.digg a:active {border-right: #000099 1px solid; Border-top: #000099 1px solid; Border-left: #000099 1px solid; COLOR: #000; Border-bottom: #000099 1px solid}
  5. Div.digg span.current {border-right: #000099 1px solid; padding-right:5px; Border-top: #000099 1px solid; padding-left:5px; Font-weight:bold; padding-bottom:2px; margin:2px; Border-left: #000099 1px solid; COLOR: #fff; padding-top:2px; Border-bottom: #000099 1px solid; Background-color: #000099}
  6. Div.digg span.disabled {border-right: #eee 1px solid; padding-right:5px; Border-top: #eee 1px solid; padding-left:5px; padding-bottom:2px; margin:2px; Border-left: #eee 1px solid; COLOR: #ddd; padding-top:2px; Border-bottom: #eee 1px solid}

PHP Code:

 
 
  1. <?php
  2. $contents = "Fjka;fjsa #page # Batch production [newpage] #page # Composition written #page# and added #page# paging code"; The original content with the paging label
  3. $cons = "Fjka;fjsa;adsfasdfas code"; Original content without pagination label
  4. function Conpage ($contents) {
  5. $pagesss = "#page #"; Set Pagination label
  6. $a =strpos ($contents, $pagesss);
  7. if ($a) {
  8. $con =explode ($pagesss, $contents);
  9. $cons =count ($con);
  10. @ $p = ceil ($_get["P"]);
  11. if (! $p $p<0) $p = 1;
  12. $url =$_server["Request_uri"];
  13. $parse _url=parse_url ($url);
  14. $url _query= $parse _url["Query"];
  15. if ($url _query) {
  16. $url _query=ereg_replace ("(^&) p= $p", "", $url _query);
  17. $url =str_replace ($parse _url["Query"), $url _query, $url);
  18. if ($url _query) $url. = "&p"; else $url. = "P";
  19. }else {
  20. $url. = "P";
  21. }
  22. if ($cons <=1) return false;//do not show paging when only one page
  23. $pagenav = "<div class=\" digg\ ">";
  24. for ($i =1; $i <= $cons; $i + +) {
  25. if ($i = = $p) {
  26. $pagenav. = "<span class=" Current ">". $p. " </span> ";
  27. }else{
  28. $pagenav. = "<a href=" $url = $i "> $i </a>";
  29. }
  30. }
  31. $pagenav. = "</div>";
  32. return $con [$p-1]. $pagenav;
  33. }else{
  34. return $contents;
  35. }
  36. }
  37. echo Conpage ($contents); With a paging label
  38. echo Conpage ($cons); With no paging label
  39. ?>

This article for PHP100 Chinese Community original works, please reprint the source: http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/1201/6940.html




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.