<?php
$sql = "SELECT COUNT(id_noticia) FROM noticias, categorias, usuarios WHERE noticias.estado = 1 AND noticias.id_categoria = categorias.id_categoria AND categorias.estado = 1 AND noticias.id_usuario = usuarios.id_usuario AND noticias.id_categoria = '".$id_cat."'";
$rs_result = mysqli_query($con, $sql);
$row = mysqli_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / $limit);
echo "<ul class='pagination'>";
if($pag != '1'){
$pagAnt = ($pag - 1);
echo "<li><a href='valle/".$id_cat."/".$pagAnt."'><i class='fa fa-angle-double-left'></i></a></li>";
}
for ($i=1; $i <= $total_pages; $i++) {
if($pag == $i){
$pagLink .= "<li class='active'><a>".$i."</a></li>";
}else{
$pagLink .= "<li><a href='valle/".$id_cat."/".$i."'>".$i."</a></li>";
}
};
echo $pagLink;
if($pag != $total_pages){
$pagSig = ($pag + 1);
echo "<li><a href='valle/".$id_cat."/".$pagSig."'><i class='fa fa-angle-double-right'></i></a></li>";
}
echo "</ul>";
?>
输出如下:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |无限
我希望它的输出是这样的:
1 | 2 | 3 | 4 | ,,, | 9
如果我在第5页输出如下:
1 | ...... | 5 | ...... | 8
我该怎么做?