Alex
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.
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.
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...
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
$cp=$page;
if ($cp<=1)
echo "<a href=\"\" class=\"toplink\"><</a>&nb
else
{
$cp--;
echo "<a href=\"yourpage.php?pageno
}
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
}
}
$forward=$page;//echo "Next";
if ($forward>=$total_pages)
echo "";
else
{
$forward++;
echo "<a href=\"yourpage.php?pageno
}
echo "<a href=\"yourpage.php?pageno
} ?>
</td>
</tr>
Please try this...
Try this
for($i=1;$i<=5;$i++) //change to ...
for($i=($total_pages-2); $i<=5;$i++)
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++)
if($total_pages<=2)
{
$start_page = 1;
} else {
$start_page = $total_pages-2;
}
for($i=$start_page;$i<=5;$
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.
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;
}
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
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
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!
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
https://www.experts-exchange.com/questions/22394235/RFC-Paginate-Class.html
http://www.plus2net.com/php_tutorial/php_paging.php
http://www.phpclasses.org/browse/package/202.html
Regards,
M.Raja