search
HomeBackend DevelopmentPHP TutorialBeautiful PHP verification code class

  1. class Page {
  2. private $total; //Total records
  3. private $pagesize; //How many records are displayed on each page?
  4. private $limit; //limit
  5. private $page; //Current page number
  6. private $pagenum; //Total page number
  7. private $url; //Address
  8. private $bothnum; //The amount of digital paging kept on both sides
  9. //Constructor method initialization
  10. public function __construct($_total, $_pagesize) {
  11. $this->total = $_total ? $_total : 1;
  12. $this->pagesize = $_pagesize;
  13. $this->pagenum = ceil($this->total / $this->pagesize) ;
  14. $this->page = $this->setPage();
  15. $this->limit = "LIMIT ".($this->page-1)*$this->pagesize.", $this->pagesize";
  16. $this->url = $this->setUrl();
  17. $this->bothnum = 2;
  18. }
  19. //Interceptor
  20. private function __get($_key ) {
  21. return $this->$_key;
  22. }
  23. //Get the current page number
  24. private function setPage() {
  25. if (!empty($_GET['page'])) {
  26. if ($_GET[ 'page'] > 0) {
  27. if ($_GET['page'] > $this->pagenum) {
  28. return $this->pagenum;
  29. } else {
  30. return $_GET['page' ];
  31. }
  32. } else {
  33. return 1;
  34. }
  35. } else {
  36. return 1;
  37. }
  38. }
  39. //Get address
  40. private function setUrl() {
  41. $_url = $_SERVER["REQUEST_URI"] ;
  42. $_par = parse_url($_url);
  43. if (isset($_par['query'])) {
  44. parse_str($_par['query'],$_query);
  45. unset($_query['page' ]);
  46. $_url = $_par['path'].'?'.http_build_query($_query);
  47. }
  48. return $_url;
  49. } //Digital directory
  50. private function pageList() {
  51. for ($i =$this->bothnum;$i>=1;$i--) {
  52. $_page = $this->page-$i;
  53. if ($_page $_pagelist .= ' '.$_page.' ';
  54. }
  55. $_pagelist .= ' < ;span class="me">'.$this->page.' ';
  56. for ($i=1;$ibothnum;$i++) {
  57. $_page = $this->page+$i;
  58. if ($_page > $this->pagenum) break;
  59. $_pagelist .= ' '.$_page.' ';
  60. }
  61. return $_pagelist;
  62. }
  63. //Homepage
  64. private function first() {
  65. if ($this ->page > $this->bothnum+1) {
  66. return ' 1 ...';
  67. }
  68. }
  69. //Previous page
  70. private function prev() {
  71. if ($this->page == 1) {
  72. return 'Previous page> ;';
  73. }
  74. return ' Previous page> ; ';
  75. }
  76. //Next page
  77. private function next() {
  78. if ($this->page == $this->pagenum) {
  79. return '';
  80. }
  81. return ' ';
  82. }
  83. //Last page
  84. private function last() {
  85. if ($this->pagenum - $this->page > $this->bothnum) {
  86. return ' ...'.$this->pagenum.' ';
  87. }
  88. }
  89. / /Paging information
  90. public function showpage() {
  91. $_page .= $this->first();
  92. $_page .= $this->pageList();
  93. $_page .= $this->last( );
  94. $_page .= $this->prev();
  95. $_page .= $this->next();
  96. return $_page;
  97. }
  98. }
  99. ?>
Copy code

The pagination style is as shown below:

Instructions for use:

  1. $_page = new Page($_total,$_pagesize); //Where $_total is the total number of items in the data set, $_pagesize is the number displayed on each page.
  2. ?>
Copy code

Verification code, PHP


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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use