I have a little issue I can't figgure out. I can't seem to figure out how to add dots to my pagination so I don't have more pagination numbers than mysql results in the page XD . This is my code:
$query = "SELECT id, .....";
$records_per_page=10;
$crud->paginglink($query,$records_per_page);
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><ul class="pagination"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<li><a href='".$self."?page_no=1'>Inceput</a></li>";
echo "<li><a href='".$self."?page_no=".$previous."' aria-label='Inapoi'><span aria-hidden='true'>«</span></a></li>";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>";
}
else
{
echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a></li>";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<li><a href='".$self."?page_no=".$next."' aria-label='Inainte'><span aria-hidden='true'>»</span></a></li>";
echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Sfarsit</a></li>";
}
?></ul><?php
}
}