php mysql jquery无刷新翻页
本站已经发布了很多无刷新翻页的,都是用的相同的数据库结构,想要查看更多请点击本站“分页”栏目
PHP Code
- <?php
- include_once('../../conn.php');
- include_once('inc/pagination.inc.php');
- $query="select id from content order by id desc";
- $res=mysql_query($query);
- $count=mysql_num_rows($res);
- if($count > 0){
- $paginationCount=getPagination($count);
- }
- ?>
- <body onload="changePagination('0','first')">
- <div id="container">
- <div id="wrapper">
- <div id="pageData"></div>
- <?php
- if($count > 0){
- ?>
- <ul>
- <li class='first link' id="first"><a href="javascript:void(0)" onclick="changePagination('0','first')">First</a></li>
- <?php
- for($i=0;$i<$paginationCount;$i++){
- ?><li id="<?php echo $i;?>_no" class='link'><a href="javascript:void(0)" onclick="changePagination('<?php echo $i;?>','<?php echo $i;?>_no')"><?php echo $i+1;?></a></li><?php
- }
- ?>
- <li class='last link' id="last"><a href="javascript:void(0)" onclick="changePagination('<?php echo $paginationCount-1;?>','last')">Last</a></li>
- <li class="flash"></li>
- </ul>
- <?php } ?>
- </div>
- </div>
JavaScript Code
- <script type="text/javascript">
- function changePagination(pageId,liId){
- $(".flash").show();
- $(".flash").fadeIn(400).html('Loading <img src="image/ajax-loading.gif" />');
- var dataString = 'pageId='+ pageId;
- $.ajax({
- type: "POST",
- url: "pageData.php",
- data: dataString,
- cache: false,
- success: function(result){
- $(".flash").hide();
- $(".link a").css('background-color','#fff') ;
- $("#"+liId+" a").css('background-color','#99A607') ;
- $("#pageData").html(result);
- }
- });
- }
- </script>
PHP Code
- pageData.php
- <?php
- include_once('../../conn.php');
- include_once('inc/pagination.inc.php');
- if(isset($_POST['pageId']) && !emptyempty($_POST['pageId'])){
- $id=$_POST['pageId'];
- }else{
- $id='0';
- }
- $pageLimit=PAGE_PER_NO*$id;
- $query="select * from content order by id desc limit $pageLimit,".PAGE_PER_NO;
- $res=mysql_query($query);
- $count=mysql_num_rows($res);
- $HTML='';
- if($count > 0){
- while($row=mysql_fetch_array($res)){
- $post=$row['message'];
- $link=$row['link'];
- $HTML.='<div>';
- $HTML.='<a href="'.$link.'" target="blank">'.$post.'</a>';
- $HTML.='</div><br/>';
- }
- }else{
- $HTML='No Data Found';
- }
- echo $HTML;
- ?>
inc/pagination.inc.php
PHP Code
- <?php
- define('PAGE_PER_NO',5);
- function getPagination($count){
- $paginationCount= floor($count / PAGE_PER_NO);
- $paginationModCount= $count % PAGE_PER_NO;
- if(!emptyempty($paginationModCount)){
- $paginationCount++;
- }
- return $paginationCount;
- }
- ?>
原文地址:http://www.freejs.net/article_fenye_433.html