I have a normal paging code, it's working correctly, but I'm not able to insert ajax into pagination.
Actually as I'm using functions, I do not know how to call the "paginglink" function in the AJAX url
Another point is that the code has $self = $_SERVER['PHP_SELF'];
that returns the current url, how do I replace the $self
variable in paging links when using Ajax?
<?php
$query = "SELECT * FROM users ORDER BY id DESC";
$records_per_page=7;
$newquery = $crud->paging($query,$records_per_page);
$crud->dataview($newquery);
?>
<tr>
<td colspan="7" align="center">
<nav aria-label="Page navigation example">
<?php $crud->paginglink($query,$records_per_page); ?>
</nav>
</td>
</tr>
class.crud.php
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 class='page-item'><a class='page-link' href='".$self."?page_no=1'>First</a></li>";
echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$previous."'>Back</a></li>";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>";
}
else
{
echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$i."'>".$i."</a></li>";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$next."'>Next</a></li>";
echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$total_no_of_pages."'>Last</a></li>";
}
?></ul><?php
}
}
Ajax:
<script>
$.ajax({
url:"???",
method:"POST",
data:,
success: ;
}
})
</script>