Hello,
I have tried to create a simple paggigation and now i am facing a problem,
I am unable to show the number of pages i.e 1 2 3
2 when i click on last page the next button is still coming up can anyone help me out .
<?php
$rec_limit = 10;
$sql = "SELECT count(uid) FROM shortenedurls";
$retval = mysqli_query($connection, $sql);
if(! $retval )
{
die('Could not get data: ' . mysqli_error());
}
$row = mysqli_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT id, uid, url, longurl ".
"FROM shortenedurls ".
"LIMIT $offset, $rec_limit";
$retval = mysqli_query($connection, $sql);
if(! $retval )
{
die('Could not get data: ' . mysqli_error($connection));
}
while($record = mysqli_fetch_array($retval)) {
$url = $record['url'];
$longurl = $record['longurl'];
$ida = $record['id'];
echo "<div class='entries'>";
echo "<div class='col-md'><a href='$longurl'>". $longurl ."</a></div>";
echo "<div class='col-md'><a href='$url'>". $url ."</a></div>";
echo "<div class='col-md smwidth1'>". $ida ."</div>";
echo "<div class='col-sm smwidth2'><a href='' data-toggle='modal' data-target='#myModal2' ><i class='fa fa-pencil-square-o'></i></a></div>";
echo "<div class='col-sm smwidth2'><a href='includes/delete.php?id=$id&delete=$ida&code=$coupen'><i class='fa fa-trash-o'></i></a></div>";
echo "<div class='clear'></div>";
echo "</div>";
}
if( $page > 0 )
{
$last = $page - 2;
$url = "coupon.php?id=$id&code=$coupen&page=$last";
echo "<a href='coupon.php?id=$id&code=$coupen&page=$last'>Previous</a> |";
echo "<a href='coupon.php?id=$id&code=$coupen&page=$page'>Next</a>";
}
else if($page == 0)
{
$last = "";
$url = "coupon.php?id=$id&code=$coupen&page=$last";
echo "<a href='coupon.php?id=$id&code=$coupen&page=$page'>Next</a>";
}
elseif( $left_rec < $rec_limit )
{
echo "<a href='coupon.php?id=$id&code=$coupen&page=$last'>Previous</a>";
}
mysqli_close($connection);
?>