function multi($num, $perpage, $curpage, $mpurl) { $multipage = ''; $mpurl .= strpos($mpurl, '?') ? '&' : '?'; if($num > $perpage) { $page = 10; $offset = 5; $pages = @ceil($num / $perpage); if($page > $pages) { $from = 1; $to = $pages; } else { $from = $curpage - $offset; $to = $curpage + $page - $offset - 1; if($from < 1) { $to = $curpage + 1 - $from; $from = 1; if(($to - $from) < $page && ($to - $from) < $pages) { $to = $page; } } elseif($to > $pages) { $from = $curpage - $pages + $to; $to = $pages; if(($to - $from) < $page && ($to - $from) < $pages) { $from = $pages - $page + 1; } } } $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" mce_href="'.$mpurl.'page=1">第一页</a> ' : '').($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).'" mce_href="'.$mpurl.'page='.($curpage - 1).'">上一页</a> ' : ''); for($i = $from; $i <= $to; $i++) { $multipage .= $i == $curpage ? $i.' ' : '<a href="'.$mpurl.'page='.$i.'" mce_href="'.$mpurl.'page='.$i.'">['.$i.']</a> '; } $multipage .= ($curpage < $pages ? '<a href="'.$mpurl.'page='.($curpage + 1).'" mce_href="'.$mpurl.'page='.($curpage + 1).'">下一页</a>' : '').($to < $pages ? ' <a href="'.$mpurl.'page='.$pages.'" mce_href="'.$mpurl.'page='.$pages.'">最后一页</a>' : ''); $multipage = $multipage ? '共'.$pages.'页: '.$multipage : ''; } return $multipage; } 用法: $pagesize = 10; // 每页记录数 $query = mysql_query("SELECT count(*) FROM table"); $row = mysql_fetch_array($query); $amount = $row[0]; // 查询记录总数 $pagecount = $amount ? (($amount < $pagesize) ? 1 : (($amount % $pagesize) ? ((int)($amount / $pagesize) + 1) : ($amount / $pagesize))) : 0; // 计算总页数 $page = !empty($_GET['page']) ? max(1, intval($_GET['page'])) : 1; $page = $page > $pagecount ? 1 : $page; // 取得当前页值 $startlimit = ($page - 1) * $pagesize; // 查询起始的偏移量 $result=mysql_query("SELECT * FROM table order by id desc LIMIT {$startlimit}, {$pagesize}"); // 查询记录集 while( $row = mysql_fetch_array($result) ) { //你要显示的格式。 } 输出页: $multipage = multi($amount, $pagesize, $page, 'index.php?action=listadmin'); // 显示分页 echo $multipage;