Reputation: 13
I have code for pagination but failed to active class. I want the click able page will be active. How can I do that with the bellow code?
<?php
$sql = "SELECT * FROM item ";
$rs_result = mysqli_query($con,$sql); //run the query
$total_records = mysqli_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
echo "<nav >
<ul class='pagination'><li class='disabled'>
<a href='myminsingbazar-en.php?Page=allAds&page=1'>".'«'."</a> </li>"; // Goto 1st page
for ($i=1; $i<=$total_pages; $i++) {
echo "<li><a href='myminsingbazar-en.php?Page=allAds&page=".$i."'>".$i."</a></li>";
};
echo "<li class='disabled'><a href='myminsingbazar-en.php?Page=allAds&page=$total_pages'>".'»'."</a> </li>
</ul>
</nav>"; // Goto last page
?>
Upvotes: 0
Views: 1698
Reputation: 2128
please try this code...
<?php
$sql = "SELECT * FROM item ";
$rs_result = mysqli_query($con, $sql); //run the query
$total_records = mysqli_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
echo "<nav>
<ul class='pagination'><li class='disabled'>
<a href='myminsingbazar-en.php?Page=allAds&page=1'>" . '«' . "</a> </li>"; // Goto 1st page
for ($i = 1; $i <= $total_pages; $i++)
{
$active = '';
if(isset($_GET['page']) && $i == $_GET['page'])
{
$active = 'class="active"';
}
echo "<li $active><a href='myminsingbazar-en.php?Page=allAds&page=" . $i . "'>" . $i . "</a></li>";
};
echo "<li class='disabled'><a href='myminsingbazar-en.php?Page=allAds&page=$total_pages'>" . '»' . "</a> </li>
</ul>
</nav>"; // Goto last page
?>
let me know if you need any further help..
Upvotes: 1