How can I limit the paging number in php?
i mean like this, example:
1 2 3 4 5
if number 3 clicked like this:
1 .. .. 4 5
or like this:
1 2 3 .. 5
or
.. 2 3 4 ..
so if too many paging numbers do not show all numbers
this my code:
$default_index = 0;
$default_batas = 2;
if(isset($_GET['batas']))
{
$default_batas = $_GET['batas'];
}
if(isset($_GET['halaman']))
{
$default_index = ($_GET['halaman']-1) * $default_batas;
}
$ambil_data = mysql_query("SELECT * FROM mytable ORDER BY id ASC Limit ".$default_index.", ".$default_batas);
$total_baris = mysql_num_rows(
mysql_query("SELECT * FROM mytable")
);
$nomor_paging = 1;
$html_paging = "<div>";
while($total_baris - $default_batas > 0)
{
$html_paging .= "<center><div><a href='?halaman=".$nomor_paging."&batas=".$default_batas."'>".$nomor_paging."</a></div>";
$nomor_paging++;
$total_baris -= $default_batas;
}
if($total_baris > 0)
{
$html_paging .= "<div><a href='?halaman=".$nomor_paging."&batas=".$default_batas."'>".$nomor_paging."</a></div></center>";
}
$html_paging .= "</div><br/>";
this the output code :
<?php echo $output_html?>
<?php echo $html_paging?>