一聚教程网:一个值得你收藏的教程网站

热门教程

ajax+php+mysql无刷新分页代码

时间:2022-06-24 18:32:03 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

  2 
  3 
  4     投票结果
  5    
  6
  7 
102
103
104
105

106

用户留言如下:


107
  
108

109

110
111


 2 $link = mysql_connect('localhost', 'root', '') or die(mysql_error());
 3 mysql_select_db('vote', $link) or die(mysql_error());
 4 mysql_query("set names utf8");
 5 $num = 3;
 6 $url = "page.php";
 7 $con = "

    ";
     8 $page = (isset($_request['page'])) ? $_request['page'] : 1;
     9 $offset = ($page - 1) * $num;
    10 $result = mysql_query("select count(*) from client");
    11 $total = mysql_fetch_row($result);
    12 $total = $total[0];
    13 $pagenum = ceil($total / $num);
    14 $page = min($pagenum, $page); //获得首页
    15 $prepg = $page - 1; //上一页
    16 if ($prepg <= 1)
    17     $prepg = 1;
    18 $nextpg = ($page == $pagenum ? 1 : $page + 1); //下一页
    19 //如果只有一页则跳出函数:
    20 if ($pagenum <= 1)
    21     return false;
    22
    23 $sql = "select `name`,`content` from `client` limit " . $offset . "," . $num;
    24 $res = mysql_query($sql);
    25 while ($content = mysql_fetch_row($res)) {
    26     $con .= "
  • $content[0]:  $content[1]
  • ";
    27 }
    28 $con .= "
";
29 $con .= <<< page
30        

首页|上一页||尾页


31
32 page;
33
34 echo $con;
35 ?>

热门栏目