$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;
}?>