首页 > PHP资讯 > HTML5培训技术 > jqueryajax无刷新翻页分页

jqueryajax无刷新翻页分页

HTML5培训技术

freejs.net已经发了不少无刷新翻页的代码,都比较实用,这边这个非常简单,适合学习或者评论使用

搜索本站可以找到更多分页代码

注意本例jq版本为1.4.3

演示

XML/HTML Code
  1. 《script》
  2. $(function(){
  3. $("#content").load("view-comments.php");
  4. //PAGE NUMBER onClick FUNCTION
  5. $(".page").live("click", function(){
  6. var page = $(this).attr("id");
  7. $("#content").load("view-comments.php?page="+page);
  8. });
  9. });
  10. 《script》
  11. view-comments.php

    PHP Code
    1. //FILE WITH THE IMPORTANT MySQL INFO
    2. include 'conn.php';
    3. //PAGE NUMBER, RESULTS PER PAGE, AND OFFSET OF THE RESULTS
    4. if($_GET["page"]){
    5. $pagenum = $_GET["page"];
    6. } else {
    7. $pagenum = 1;
    8. }
    9. $rowsperpage = 3; //MAXIMUM RESULTS PER PAGE
    10. $offset = ($pagenum - 1) * $rowsperpage; //WHERE THE RESULTS START FROM
    11. $table="content";
    12. //FOR RESULTS OF THE PAGE
    13. $q = mysql_query("SELECT * FROM $table ORDER BY id LIMIT $offset, $rowsperpage");
    14. $page_nums = mysql_num_rows($q); //NUMBER OF RESULTS FOR THE PAGE
    15. $total_q = mysql_query("SELECT * FROM $table"); //FOR THE ALL RESULTS
    16. $total_nums = mysql_num_rows($total_q); //TOTAL NUMBER OF RESULTS
    17. $total_pages = ceil($total_nums/$rowsperpage); //NUMBER OF PAGES
    18. //IF PAGE NUMBER IS WITHIN THE FIRST AND LAST PAGES
    19. if($pagenum>=1&&$pagenum<=$total_pages)
    20. {
    21. while($r=mysql_fetch_array($q))
    22. {
    23. $content = $r["name"];
    24. echo '
      '.$content.'
      ';
    25. }
    26. echo '
      ';
    27. //IF ANY RESULTS
    28. if($total_nums)
    29. {
    30. $range = 2; //NUMBER OF PAGES TO BE SHOWN BEFORE AND AFTER THE CURRENT PAGE NUMBER
    31. //FIRST, PREVIOUS, NEXT, AND LAST LINKS
    32. if($pagenum>1)
    33. {
    34. $page = $pagenum - 1;
    35. $first = '

HTML5培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持42不支持0