0

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);      

                    ?>      
3
Contributors
6
Replies
18
Views
2 Years
Discussion Span
Last Post by pritaeas
0

changed but still the same issue on the second page there are only 4 listings though and still showing the next button as accroding to the condition it should show only last button

0

I think value of id is missing.

in line 37 $ida = $record['id'];

in line 54

<a href='coupon.php?id=$id&code=$coupen&page=$last'>

0

I put else if as well like if the records are less then 10 so it should show only last button not next..if this logic is wrong can you suggest me i was also thinking of page login but was really confused

0

You should write it with if's, not with else-if's. You have a previous button when the page you are on is larger than the first page (0). You have a next link when the page you are on is smaller than the last page.

I wrote a pagination example on this forum as a reply.

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.