Demo of Pagination of student table using Boostrap4 classes
ID | NAME | CLASS | MARK | SEX |
1 | John Deo | Four | 49 | female |
2 | Max Ruin | Three | 3 | male |
3 | Arnold | Three | 5 | male |
4 | Krish Star | Four | 60 | female |
5 | John Mike | Four | 20 | female |
require "config.php"; // database details
$set_page_name="bs4_pagination.php";
$set_table_name="student";
///////////////
date_default_timezone_set ("Asia/Calcutta");
@$start=$_GET['start'];
if(!isset($start)) {
$start = 0;
}
$eu = $start;
$limit = 5; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$ant = $back + 1;
$nume = $dbo->query("select count(id) from student")->fetchColumn();
$q="SELECT * from student";
$query="$q limit :start,:limit ";
$step = $dbo->prepare($query);
$start=(int)$start;
$step->bindParam(':start', $start,PDO::PARAM_INT,3);
$step->bindParam(':limit', $limit,PDO::PARAM_INT,3);
$step->execute();
$step = $step->fetchAll();
// display records ////
echo "<table class='table table-striped'>
<thead class='thead-dark'>
<tr><th>ID</th><th>NAME</th><th>CLASS</th><th>MARK</th><th>SEX</th></tr>
</thead> ";
foreach ($step as $row) {
echo "<tr><td>$row[id]</td><td>$row[name]</td><td>$row[class]</td><td>$row[mark]</td><td>$row[sex]</td></tr>";
}
echo "</table>";
////////// paging strat///
/////
echo "<nav aria-label='Student Table Listing in $number_of_pages Pages'><ul id=p1 class='pagination justify-content-center pagination-lg'>";
if($ant >= 1) {
$set_previous='';
} else {
$set_previous='disabled';
}
print "<li class='page-item $set_previous'><a href='$set_page_name?start=$back' class='page-link' tabindex='-1'><span aria-hidden='true'>«</span></a></li>";
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo "<li class='page-item'> <a href='$set_page_name?start=$i' class='page-link'>$l</a> </li>";
}
else { echo "<li class='page-item active'><span class='page-link'>$l<span class='sr-only'>(current)</span>
</span> </li>";}
$l=$l+1;
}
if($this1 < $nume) {
$set_next='';
} else{
$set_next='disabled';
}
echo "<li class='page-item $set_next'><a href='$set_page_name?start=$next' class='page-link'><span aria-hidden='true'>»</span></a></li>";
echo "</ul></nav>
</div></div>";