search

In this program, the new class FENYE inherits the class DBSQL, so in the destructor of the new class, the destructor of the parent class is called to connect to the database, and the file config.inc.php that defines the global variables is also included.
  1. /*
  2. There are three class functions in this paging class. The function of the first function is mentioned above. The second function caculate is mainly to calculate the total number of records in the record set and how many to divide. The page is displayed, and these results are assigned to member variables so that the next function can use these values. The third function, url, is the code that implements paging display of the record set. Let me talk about it here. The paging algorithm mainly uses this SQL statement: select * from table_name limit $start, $pageper; among them, $start is the starting position of the query, and $pageper is the number of items to be displayed on each page. .
  3. */
  4. include_once("db.inc.php");
  5. class FENYE extends DBSQL{
  6. public $count_1; //Return the total number of result record sets
  7. private $pageper=3; //Each Number of record sets displayed on the page
  8. public $pc; //Total number of pages displayed
  9. private $sql="select * from students";
  10. public $offset; //Current page number
  11. public function __contract (){
  12. parent::__contract(); //Call the method in the parent class to connect to the database
  13. }
  14. public function caculate($sql=""){
  15. $sql=$this->sql;
  16. $result=mysql_query($sql) or die (mysql_error());
  17. $count=mysql_num_rows($result);
  18. $this->count_1=$count;
  19. $pc=intval($count /$this->pageper)+1;
  20. $this->pc=$pc;
  21. }
  22. public function url($targetUrl){
  23. $pagesize=$this->pageper ; // Display records on each page
  24. $page=isset($_GET['page'])?intval($_GET['page']):1;//Get the current page
  25. $sql="select * from students limit " .($page-1)*$pagesize.",$pagesize";
  26. //echo $sql ;exit;
  27. $results=mysql_query($sql) or die (mysql_error());
  28. while ($ row = mysql_fetch_array($results)){
  29. for($i=0;$i
  30. echo $row[$i]."    " ;
  31. echo "
    ";
  32. }
  33. $offset=($page-1)*$pagesize;
  34. $prepage=$page-1; //Previous page
  35. $nextpage=$ page+1; //Next page
  36. $pagenav="Total ".$this->count_1." records Each page displays $pagesize records, a total of ".$this->pc." page, current Page $page";
  37. if($page==1){
  38. $strpage="[First page][Previous page][ Next page][Last page]";
  39. }
  40. if($page>1&&$page< ;=$this->pc){
  41. $strpage="[First page]【Previous page】【Next page】[Last page]";
  42. }
  43. if($page==$this->pc){
  44. $strpage="【First page】【Previous page】【Next Page】【Last page】";
  45. }
  46. $strpage="$pagenav
    $strpage";
  47. echo $strpage;
  48. }
  49. }
  50. /*
  51. Small function annotation:
  52. intval: Get an integer value;
  53. count: Calculate the number of elements in an array;
  54. expression_1? expression_2:expression_3;: If the first expression is a value, the return value of this function is the value of the second expression, otherwise the return value of the function is the value of the third expression.
  55. For the safety of the program code, set the type of the member variables of the class to private. */
  56. ?>
Copy code


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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),