Php+mysql page Break

Source: Internet
Author: User
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 link the database, and the file config.inc.php defined by the global variable is included.
  1. /*
  2. There are three class functions in this paging class, the function of the first function says, the second function Caculate mainly calculates the total number of records in the recordset, how many pages are displayed, and assigns the results to the member variables for the next function to use the values. The third function, the URL, is the code that implements the recordset pagination display. Here, the paging algorithm mainly uses this SQL statement: SELECT * FROM table_name limit $start, $pageper; where $start is the starting position of the query, $pageper is the number of bars to display on each page.
  3. */
  4. Include_once ("db.inc.php");
  5. Class Fenye extends dbsql{
  6. Public $count _1; Returns the total number of bars in the result recordset
  7. Private $pageper = 3; Number of recordset bars displayed per page
  8. Public $pc; Total number of pages displayed
  9. Private $sql = "SELECT * from students";
  10. Public $offset; The current number of pages
  11. Public Function __constract () {
  12. Parent::__constract (); Call a method in the parent class to link 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; Show records per 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 $pagesize records per page, total". $this->pc. "Page, current section $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 Annotations:
  52. Intval: Obtain an integer value;
  53. Count: Computes the number of elements of an array;
  54. Expression_1? Expression_2:expression_3;: If the first expression is a value, the return value of the 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 security of the Code of the program, the type of the member variable of the class is set to private. */
  56. ?>
Copy Code
  • 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.