0

i want to hide some of the page numbers after 5 till last but one this is my code

<?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 "<a href='".$self."?page_no=1'>First</a>&nbsp;&nbsp;";
                echo "<a href='".$self."?page_no=".$previous."'>Previous</a>&nbsp;&nbsp;";
            }

            for($i=1;$i<=$total_no_of_pages;$i++)
            {
                if($i==$current_page)
                {
                    echo "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a></strong>&nbsp;&nbsp;";
                }
                else
                {
                    echo "<a href='".$self."?page_no=".$i."'>".$i."</a>&nbsp;&nbsp;";
                }
            }

            if($current_page!=$total_no_of_pages)
            {
                $next=$current_page+1;
                echo "<a href='".$self."?page_no=".$next."'>Next</a>&nbsp;&nbsp;";
                echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a>&nbsp;&nbsp;";
            }
            ?>

i know i need to edit in meddle of the code like

for($i=1;$i<=$total_no_of_pages;$i++)
            {
                if($i==$current_page)
                {
                    echo "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a></strong>&nbsp;&nbsp;";
                }
                else
                {
                    echo "<a href='".$self."?page_no=".$i."'>".$i."</a>&nbsp;&nbsp;";
                }
            }

is it possible to make it with small corrections please don't make it duplicate because i did't get the answer which is required

Thanks in advance

Asesha George
  • 2,232
  • 2
  • 32
  • 68
  • Check another this -[https://stackoverflow.com/questions/limit-the-number-of-visible-pages-in-pagination](https://stackoverflow.com/questions/46382109/limit-the-number-of-visible-pages-in-pagination) – Pranta Saha Oct 08 '19 at 13:34

1 Answers1

0

What about that?

$x="";

for($i=1;$i<=$total_no_of_pages;$i++) {
  if($i==$current_page) {
     $x.= "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a></strong>&nbsp;&nbsp;";
  } 
  elseif ($i>4 && $i!=$total_no_of_pages) {
     $x.= ".";
  }
  else {
     $x.= "<a href='".$self."?page_no=".$i."'>".$i."</a>&nbsp;&nbsp;";
  }
}
echo $x;
Jeff
  • 6,895
  • 1
  • 15
  • 33
  • ya that's what i want thank you. but got a problem please see the link it converted all the numbers in to dots i see to many dots. http://bankhints.com/ifsc-bank.php?page_no=8 – Asesha George Jul 26 '15 at 14:35
  • haha, yes, because it's 357 pages! I didnt expect so many... solution: replace `$x.= ".";` with `$x.= " ";` – Jeff Jul 26 '15 at 14:49
  • hmmm i did the same now its working fine. grate answer jeff. thank you very much – Asesha George Jul 26 '15 at 14:53