Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for Greece

asked on

Pagination

Hi

I need pagination...
I get about 45 results.
6 results / page.

I've done the pagination BUT i want to scroll the pages
(
like here in EE : https://www.experts-exchange.com/CH_3701409.html?chStart=31&chOrderBy=1&chSort=-1#ch 
)

example :
<< < 1 2 3 4 5 > >> when i press 5 i want to show : << <3 4 5 6 7 > >>
when i press 6 i want to show : << < 4 5 6 7 8 > >>
....etc and the opposite when i press 6

Thanks in advance.
Avatar of raja_ind82
raja_ind82
Flag of India image

Avatar of Alex

ASKER

Thanks for your post ... but...
I just want the code for the "for" statement..
I've already finished the paging system... I just want the numbers to scroll like i described...
Could you post your code for the for-loop then its easier for us to extend your code

<tr>      
<?      
$total_pages=5;
if ($total_pages>1)
      {      ?>
      <td class="normaltext12"><b> Result pages:</td>
      <td  align="" width="75%" class="paging_text" colspan="2">
<?                        
            echo "<a href=\"yourpage.php?pageno=1\" class=\"toplink\"><<</a>&nbsp;&nbsp;";
      $cp=$page;
      if ($cp<=1)
            echo "<a href=\"\" class=\"toplink\"><</a>&nbsp;&nbsp;";
      else
      {
            $cp--;
            echo "<a href=\"yourpage.php?pageno=$cp\" class=\"toplink\"><</a>&nbsp;&nbsp;";
      }

                  for($i=1;$i<=5;$i++)
                  {
                        if($i<=$total_pages)

                              {
                                    if($i==$page)
                                    {
                                    ?> <b><font color="red"><?echo $i ; ?></font> </b>
                                    <?
                                    }
                                    else
                                    echo "<a href=\"yourpage.php?pageno=$i\" class=\"toplink\">$i&nbsp;</a>";
                              }
                  }
      $forward=$page;//echo "Next";
      if ($forward>=$total_pages)
            echo "";
      else
      {
            $forward++;      
            echo "<a href=\"yourpage.php?pageno=$forward\" class=\"toplink\"> > </a>&nbsp;&nbsp;";
      }

                  echo "<a href=\"yourpage.php?pageno=$total_pages\" class=\"toplink\"><<</a>&nbsp;&nbsp;";
} ?>
</td>                        
</tr>

Please try this...
Try this

for($i=1;$i<=5;$i++) //change to ...

for($i=($total_pages-2); $i<=5;$i++)
Actually, this would be more appropriate

if($total_pages<=2)
{
  $start_page = 1;
} else {
  $start_page = $total_pages-2;
}
for($i=$start_page;$i<=5;$i++)


Avatar of Alex

ASKER

Oh guys thank you very much for your fast response but maybe i must be more specific...

So... we have this example to make things more clear ;)

<< <  1 2 3 4 5 > >> If i click on 4 for example i must take as result this...

<< < 2 3 4 5 6 > >>

So i want an empty page... forget pagination
Just with these numbers ...
when i click one number (with GET) i want to see 2 numbers on the right 2 on the left.
I would try the following code for such a for-loop:
$startvalue = $_GET['page']-2;
if ($startvalue > ($numpages -2)) $startpage = $numpages -2;
if ($startvalue <3) $startvalue = 1;
for ($i = 0; $i <= 5; ++$i) {
echo $startvalue + $i;
}
ASKER CERTIFIED SOLUTION
Avatar of zsoder
zsoder
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There's a pagination script you can easily modify to your needs. It does exactly what you are looking for.
The comment section at the top isn't formated quite right .. but the script is sound. I've tested it about every way I know how to break it. I'm probably gonna convert it to a class .. would be easier to work with and more modular.
Avatar of Alex

ASKER

wow!!!! man this was great thank a lot!!!! with a few modifications your code working perfect for me ... ;)
Thanks alex,

Have you ever worked with classes? .. by tomorrow I should have the code setup entirely in a class, which will allow you reuse the code in pretty much anysite .. let me know if you want me to send you the class code when I'm done
Avatar of Alex

ASKER

yes i had worked with classes and ... yes i'd like to send me the class! I will leave tomorrow from my town for a few days and i'll return back on Tuesday so if you will do something until Tuesday i'll see it when i return.

Thanks again!  
Got the class done .. posted in a RFC .. here's the link

https://www.experts-exchange.com/questions/22394235/RFC-Paginate-Class.html