Jump to content

[SOLVED] Please help. Pagination code in config file.


Recommended Posts

Dear members,

 

I am facing a problem in my websites pagination, in index.php file i am using this php code.

 

PageNavigation($pageno,$totalPages,$query);

 

And in config.php i am using this code.

 

function PageNavigation($pageno,$totalPages,$query){

    ?>

        <table align="center" border="0" cellpadding="3" cellspacing="0">

            <tr>

                <!--<td class="pager">Page:</td>-->

                <?php

                    if($pageno!=1){

                        $hr = $query."pageno=1";

                        echo"<td class='pager'><a href='$hr' class='pager'>First</a></td>";

                        $a = $pageno-1;

                        $hr = $query."pageno=".$a;

                        echo"<td class='pager'><a href='$hr' class='pager'>Back</a></td>";

                    }

                    $i = 1;           

                    while($i <= $totalPages){

                        $hr = $query."pageno=".$i;

                        if($i == $pageno){

                            echo"<td class='pagerOn'><b>$i</b></td>";

                        }else{

                            echo"<td class='pager'><a href='$hr' class='pager'>$i</a></td>";

                        }

                        $i++;

                    }

                    if($pageno!=$totalPages){

                        $a = $pageno+1;

                        $hr = $query."pageno=".$a;

                        echo"<td class='pager'><a href='$hr' class='pager'>Next</a></td>";

                        $hr = $query."pageno=".$totalPages;

                        echo"<td class='pager'><a href='$hr' class='pager'>Last</a></td>";

                    }

                ?>

                <!--<td class="pager"> (<?php echo $totalPages;?> total)-->

            </tr>

        </table>

<?php

    }

?>

 

The problem is that, all page numbers is showing on index file. As example.

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Next Previous

 

But i want to change it with 10 pages on index file. And i want to change the pagination like this. As example.

 

Previous 1 2 3 4 5 6 7 8 9 10..14 15 Next

 

Please help me to change the pagination. I'll be very thankful to you.

You should change

 

$i = 1;           
                    while($i <= $totalPages){
                        $hr = $query."pageno=".$i;
                        if($i == $pageno){
                            echo"<td class='pagerOn'><b>$i</b></td>";
                        }else{
                            echo"<td class='pager'><a href='$hr' class='pager'>$i</a></td>";
                        }
                        $i++;
                    }

 

to something like

 


$i = ($pageno - 5) > 0 ? ($pageno - 5) : 1;           
                    while($i <= $totalPages && $i < $pageno + 5){
                        $hr = $query."pageno=".$i;
                        if($i == $pageno){
                            echo"<td class='pagerOn'><b>$i</b></td>";
                        }else{
                            echo"<td class='pager'><a href='$hr' class='pager'>$i</a></td>";
                        }
                        $i++;
                    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.