freejs.net已经发了不少无刷新翻页的代码,都比较实用,这边这个非常简单,适合学习或者评论使用
搜索本站可以找到更多分页代码
注意本例jq版本为1.4.3
演示
XML/HTML Code
- 《script》
- $(function(){
- $("#content").load("view-comments.php");
-
- //PAGE NUMBER onClick FUNCTION
- $(".page").live("click", function(){
- var page = $(this).attr("id");
- $("#content").load("view-comments.php?page="+page);
- });
- });
- 《script》
-
view-comments.php
PHP Code-
- //FILE WITH THE IMPORTANT MySQL INFO
- include 'conn.php';
-
- //PAGE NUMBER, RESULTS PER PAGE, AND OFFSET OF THE RESULTS
- if($_GET["page"]){
- $pagenum = $_GET["page"];
- } else {
- $pagenum = 1;
- }
-
- $rowsperpage = 3; //MAXIMUM RESULTS PER PAGE
- $offset = ($pagenum - 1) * $rowsperpage; //WHERE THE RESULTS START FROM
-
- $table="content";
- //FOR RESULTS OF THE PAGE
- $q = mysql_query("SELECT * FROM $table ORDER BY id LIMIT $offset, $rowsperpage");
- $page_nums = mysql_num_rows($q); //NUMBER OF RESULTS FOR THE PAGE
-
- $total_q = mysql_query("SELECT * FROM $table"); //FOR THE ALL RESULTS
- $total_nums = mysql_num_rows($total_q); //TOTAL NUMBER OF RESULTS
- $total_pages = ceil($total_nums/$rowsperpage); //NUMBER OF PAGES
-
- //IF PAGE NUMBER IS WITHIN THE FIRST AND LAST PAGES
- if($pagenum>=1&&$pagenum<=$total_pages)
- {
- while($r=mysql_fetch_array($q))
- {
- $content = $r["name"];
- echo '';
- }
-
- echo '
'; -
- //IF ANY RESULTS
- if($total_nums)
- {
- $range = 2; //NUMBER OF PAGES TO BE SHOWN BEFORE AND AFTER THE CURRENT PAGE NUMBER
-
- //FIRST, PREVIOUS, NEXT, AND LAST LINKS
- if($pagenum>1)
- {
- $page = $pagenum - 1;
- $first = '