如何在我的分页中添加省略号(三个点)?

时间:2010-08-06 12:40:11

标签: php mysql pagination

  

可能重复:
  how to add ellipsis to pagination?

如何添加...到这个分页脚本(1 2 3 4 ... 14 15 16)

if (isset($_GET['p'])) {
   $pageno = $_GET['p'];
} else {
   $pageno = 1;
} // if
$query = mysql_query("SELECT count(id) FROM m3_musicblog");
$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 4;
$lastpage      = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
if ($pageno < 1) {
   $pageno = 1;
} // if
$limit = 'ORDER BY id DESC LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = mysql_query("SELECT * FROM m3_musicblog $limit");
if ($pageno == 1) {
   echo "<a>««</a> <a>«</a> ";
} else {
   echo " <a href='music-news?p=1'>««</a> ";
   $prevpage = $pageno-1;
   echo " <a href='music-news?p=$prevpage'>«</a> ";
} // if

for($page_number = 1; $page_number <= $lastpage; $page_number++)
if($page_number == $pageno) {
echo "<span class='current'>$pageno</span>";
}
else {
echo "<a href='music-news?p=$page_number' class='page' title='$page_number'>$page_number</a>";
}

if ($pageno == $lastpage) {
   echo " <a>»</a> <a>»»</a> ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='music-news?p=$nextpage'>»</a> ";
   echo " <a href='music-news?p=$lastpage'>»»</a> ";
} // if

0 个答案:

没有答案