PHP + MYSQL page feed

Source: Internet
Author: User
PHP + MYSQL page feed
In this program, the new class FENYE inherits the class DBSQL. Therefore, in the new class destructor, the parent class destructor is called to connect to the database, the config file contains the global variable definition. inc. php.

  1. /*
  2. There are three class functions in this paging class. The first function is used to calculate the total number of records in the second function caculate, at the same time, these results are assigned to member variables for the next function to use these values. The third function, url, is the code that enables pagination of record sets. Here, the paging algorithm mainly uses this SQL statement: select * from table_name limit $ start, $ pageper; where $ start is the start position of the query, $ pageper indicates the number of entries to be displayed on each page.
  3. */
  4. Include_once ("db. inc. php ");
  5. Class FENYE extends DBSQL {
  6. Public $ count_1; // total number of returned result Records
  7. Private $ pageper = 3; // number of records displayed on each page
  8. Public $ pc; // The total number of displayed pages
  9. Private $ SQL = "select * from students ";
  10. Public $ offset; // Current page number
  11. Public function _ constract (){
  12. Parent: :__ constract (); // call the method in the parent class to link 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; // records displayed 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. "$ pagesize records are displayed on each page ". $ this-> pc. "page, current $ 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: returns an integer;
  53. Count: calculates 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 sake of program code security, but set the class member variable type to private. */
  56. ?>

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.