search

Encapsulated class:
  1. /*********************************************
  2. Class name: PageSupport
  3. Function : Display data in mysql database in pages
  4. ***************************************** ******/
  5. class PageSupport{
  6. //Attributes
  7. var $sql; //SQL query statement of the data to be displayed
  8. var $page_size; // The maximum number of rows displayed on each page
  9. var $start_index; //The serial number of the first row of the record to be displayed
  10. var $total_records; //The total number of records
  11. var $current_records; //The number of records read on this page
  12. var $result; / /Reading results
  13. var $total_pages; //Total number of pages
  14. var $current_page; //Current number of pages
  15. var $display_count = 30; //Number of previous and next pages displayed
  16. var $arr_page_query ; //Array, containing parameters that need to be passed for paging display
  17. var $first;
  18. var $prev;
  19. var $next;
  20. var $last;
  21. //Method
  22. /*******************************************
  23. Constructor: __construct()
  24. Input parameters:
  25. $ppage_size: Maximum number of lines displayed per page
  26. *********************************** ************/
  27. function PageSupport ($ppage_size)
  28. {
  29. $this->page_size=$ppage_size;
  30. $this->start_index=0;
  31. }
  32. /*********************************************
  33. Constructor: __destruct()
  34. Input parameters:
  35. ********************************************* **/
  36. function __destruct()
  37. {
  38. }
  39. /*******************************************
  40. get function: __get()
  41. *************************************************/
  42. function __get($property_name)
  43. {
  44. if(isset($this->$property_name))
  45. {
  46. return($this->$property_name);
  47. }
  48. else
  49. {
  50. return(NULL);
  51. }
  52. }
  53. /*******************************************
  54. set function: __set()
  55. ***********************************************/
  56. function __set($property_name, $value)
  57. {
  58. $this->$property_name = $value;
  59. }
  60. /*********************************************
  61. Function name: read_data
  62. Function : Read the corresponding records from the table according to the SQL query statement
  63. Return value: attribute two-dimensional array result [record number] [field name]
  64. ******************* ****************************/
  65. function read_data()
  66. {
  67. $psql=$this->sql;
  68. //Query data, database link and other information should be implemented outside the class call
  69. $result=mysql_query ($psql) or die(mysql_error());
  70. $this->total_records=mysql_num_rows($result);
  71. //Use the LIMIT keyword to get the records to be displayed on this page
  72. if($this->total_records> ;0)
  73. {
  74. $this->start_index = ($this->current_page-1)*$this->page_size;
  75. $psql=$psql. " LIMIT ".$this->start_index." , ".$this->page_size;
  76. $result=mysql_query($psql) or die(mysql_error());
  77. $this->current_records=mysql_num_rows($result);
  78. //Put the query results In the result array
  79. $i=0;
  80. while($row=mysql_fetch_Array($result))
  81. {
  82. $this->result[$i]=$row;
  83. $i++;
  84. }
  85. }
  86. //Get the total number of pages and current page information
  87. $this->total_pages=ceil($this->total_records/$this->page_size);
  88. $this->first=1;
  89. $this- >prev=$this->current_page-1;
  90. $this->next=$this->current_page+1;
  91. $this->last=$this->total_pages;
  92. }
  93. /*********************************************
  94. 函数名:standard_navigate()
  95. 功能: 显示首页、下页、上页、未页
  96. ***********************************************/
  97. function standard_navigate()
  98. {
  99. echo "
    ";
  100. echo "
    ";
  101. echo "第".$this->current_page."页/共".$this->total_pages."页";
  102. echo " ";
  103. echo "跳到页";
  104. echo "";
  105. //生成导航链接
  106. if ($this->current_page > 1) {
  107. echo "first.">首页|";
  108. echo "prev.">上一页|";
  109. }
  110. if( $this->current_page total_pages) {
  111. echo "next.">下一页|";
  112. echo "last.">末页";
  113. }
  114. echo "
  115. ";
  116. echo "
";
  • }
  • /*********************************************
  • Function name: full_navigate()
  • Function: Display homepage, next page, previous page, and next page
  • Generate navigation links such as 1 2 3... 10 11
  • ********************** *************************/
  • function full_navigate()
  • {
  • echo "
    ";
  • echo "
    ";
  • echo "第".$this->current_page."页/共".$this->total_pages."页";
  • echo " ";
  • echo "跳到页";
  • echo "";
  • //生成导航链接 如1 2 3 ... 10 11
  • $front_start = 1;
  • if($this->current_page > $this->display_count){
  • $front_start = $this->current_page - $this->display_count;
  • }
  • for($i=$front_start;$icurrent_page;$i++){
  • echo "[".$i ."] ";
  • }
  • echo "[".$this->current_page."]";
  • $displayCount = $this->display_count;
  • if($this->total_pages > $displayCount&&($this->current_page+$displayCount)total_pages){
  • $displayCount = $this->current_page+$displayCount;
  • }else{
  • $displayCount = $this->total_pages;
  • }
  • for($i=$this->current_page+1;$i echo "[".$i ."] ";
  • }
  • //生成导航链接
  • if ($this->current_page > 1) {
  • echo "first.">首页|";
  • echo "prev.">上一页|";
  • }
  • if( $this->current_page total_pages) {
  • echo "next.">下一页|";
  • echo "last.">末页";
  • }
  • echo "
  • ";
  • echo "
  • ";
  • }
  • }
  • ?>
  • 复制代码
    Code written in the php page:
    1. include_once("fenye_php.php"); //Introduce the class
    2. ///// ///////////////////////////////////////////////////// ////////////////
    3. $con = mysql_connect("localhost","root","");
    4. if (!$con)
    5. {
    6. die('Could not connect : ' . mysql_error());
    7. }
    8. mysql_select_db("myblog", $con); //Select database
    9. $PAGE_SIZE=10; //Set the number displayed on each page
    10. /////// ///////////////////////////////////////////////////// //////////////
    11. $pageSupport = new PageSupport($PAGE_SIZE); //Instantiate the PageSupport object
    12. $current_page=$_GET["current_page"];//Page the current page Count
    13. if (isset($current_page)) {
    14. $pageSupport->__set("current_page",$current_page);
    15. } else {
    16. $pageSupport->__set("current_page",1);
    17. }
    18. $pageSupport->__set("sql","select * from article ");
    19. $pageSupport->read_data();//Read data
    20. if ($pageSupport->current_records > ; 0) //If the data is not empty, assemble the data
    21. {
    22. for ($i=0; $icurrent_records; $i++)
    23. {
    24. $title = $pageSupport->result[ $i]["title"];
    25. $content = $pageSupport->result[$i]["content"];
    26. $part=substr($content,0,400);
    27. //Loop to output each piece of data
    28. echo '
    29. '.$title.'
    30. '.$part .'
    31. update delet
  • ';
  • }
  • }
  • $pageSupport->standard_navigate(); //Call this function in the class to display paging HTML
  • //Close the database
  • mysql_close($con );
  • ?>
  • Copy code
    From: http://blog.csdn.net/phpfenghuo/article/details/23207099
    Pagination, php, mysql


    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
    PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

    PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

    PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

    PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

    PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

    PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

    The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

    PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

    PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

    PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

    PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

    PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

    PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

    PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

    PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

    PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    WWE 2K25: How To Unlock Everything In MyRise
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    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