Hi,

Need help, im stuck here in PHP pagination, though i have made it work but it displays all the nmuber of pages i have. My goal is to have an adjacent so that it would be more clean for the user. here are the fucntion code for my pagination, my problem is where to insert that adjacents (...)

public function paging($query,$records_per_page)
    {
        $starting_position=0;
        if(isset($_GET["page_no"]))
        {
            $starting_position=($_GET["page_no"]-1)*$records_per_page;
        }
        $query2=$query." limit $starting_position,$records_per_page";
        return $query2;
    }

    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><a href='".$self."?page_no=1'>First</a></li>";
                echo "<li><a href='".$self."?page_no=".$previous."'>Previous</a></li>";
            }
            for($i=1;$i<=$total_no_of_pages;$i++)
            {
                if($i==$current_page)
                {
                    echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>";
                }
                else
                {
                    echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a></li>";
                }
            }
            if($current_page!=$total_no_of_pages)
            {
                $next=$current_page+1;
                echo "<li><a href='".$self."?page_no=".$next."'>Next</a></li>";
                echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Last</a></li>";
            }
            ?></ul><?php
        }
    }

Thanks guys!!!

Member Avatar for diafol

What do you mean where to put it? Where do you want to put it?

Member Avatar for diafol

There are many designs for pagination / navigation of pages. Most have first/prev/numbered(continous or few contiguous)/next/last construct. You can make these dynamic (e.g. drop first/prev or next/last, move the contiguous or truncated series), depending on the number of pages or your current location within the series. Can you show examples of the type of output you're looking for?

Hi Diafol,

pagination.PNG

It shows all page number. then what im trying to do here is like this
first <previous 123...789 next> last

Thanks in advance for the reply

Did you manage to fix it? I'm having a similar issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.