php mysql ajax 分页_jQuery+Ajax+PHP+Mysql实现分页显示数据

$cur_page = $page; //当前页数

$page -= 1;$per_page = 10;$previous_btn = true;$next_btn = true;$first_btn = true;$last_btn = true;$start = $page * $per_page; //0 10 20 30 40 第一页:page = 1

//数据库配置信息

define("HOST","localhost"); //主机名

define("USER","root"); //账号

define("PASS","root"); //密码

define("DBNAME","waterfall"); //数据库名

$link = mysql_connect("localhost","root","root")or die("连接数据库失败:".mysql_error());mysql_select_db("waterfall",$link);mysql_query("set NAMES ‘utf8‘");$query_page_data = "SELECT * FROM `content` LIMIT $start, $per_page";$result_page_data = mysql_query($query_page_data) or die(‘MySql Error‘ . mysql_error());$msg = "";while ($row = mysql_fetch_array($result_page_data)) {$htmlmsg=htmlspecialchars($row[‘img‘]);$msg .= "

" . $row[‘id‘] . " " . $htmlmsg . "";

}$msg = "

  • " . $msg . "
"; //数据内容

/*---------------------------------------------*/

$query_pag_num = "SELECT COUNT(*) AS count FROM content";$result_pag_num = mysql_query($query_pag_num);$row = mysql_fetch_array($result_pag_num);$count = $row[‘count‘];$no_of_paginations = ceil($count / $per_page);/*---------------计算该循环的起始和endign值-----------------------------------*/

if ($cur_page >= 7) {$start_loop = $cur_page - 3;if ($no_of_paginations > $cur_page + 3)$end_loop = $cur_page + 3;else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {$start_loop = $no_of_paginations - 6;$end_loop = $no_of_paginations;

}else{$end_loop = $no_of_paginations;

}

}else{$start_loop = 1;if ($no_of_paginations > 7)$end_loop = 7;else

$end_loop = $no_of_paginations;

}/*-----------------------------------------------------------------------------------------------------------*/

$msg .= "

  • ";//为使第一个按钮

if ($first_btn && $cur_page > 1) {$msg .= "

First";

}else if ($first_btn) {$msg .= "

First";

}//为使上一个按钮

if ($previous_btn && $cur_page > 1) {$pre = $cur_page - 1;$msg .= "

Previous";

}else if ($previous_btn) {$msg .= "

Previous";

}for ($i = $start_loop; $i <= $end_loop; $i++) {if ($cur_page == $i)$msg .= "

{$i}";else

$msg .= "

{$i}";

}//为使下一个按钮

if ($next_btn && $cur_page < $no_of_paginations) {$nex = $cur_page + 1;$msg .= "

Next";

}else if ($next_btn) {$msg .= "

Next";

}// 要启用结束按钮

if ($last_btn && $cur_page < $no_of_paginations) {$msg .= "

Last";

}else if ($last_btn) {$msg .= "

Last";

}$goto = "";$total_string = "Page " . $cur_page . " of $no_of_paginations";$msg = $msg . "

" . $goto . $total_string . "
"; //为分页内容

echo $msg;

}?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值