Jump to content

Recommended Posts

Hello, everyone. I am having some trouble figuring this out. I am trying to create a paging bar(so to speak) to display results by page number.

Trying to get the paging bar to go as follows...

Requested Page    The resulting paging bar

Page 1                    1 2 3 4 5

Page 2                    1 2 3 4 5

Page 3                    1 2 3 4 5

Page 4                    1 2 3 4 5

Page 5                    4 5 6 7 8

Page 6                    4 5 6 7 8

Page 7                    4 5 6 7 8

Page 8                    7 8 9 10 11

......

This is what I have right now that I am trying to get to work. I have changed this so many times and been working on it for 2 days. I think I'm just confusing my self. This can't be that hard..  :(

<?php
echo '<html>';
//---these values changed based on query----
$Page=$_GET["page"]; //the page number requested
$AvailablePages=5; //number of pages available after the page requested

//---calculations---
$StartPage=round($Page/5)*5;
$EndPage=ceil($StartPage/5)*5 ; //the last page number to be displayed in paging
if($StartPage<5) {$StartPage=1;}

//just looking at variables
echo 'page is: ' . $Page . '<br>';
echo '<br>Starting @: ' . $StartPage;
echo '<br>Ending @: ' . $EndPage . '<br>';

//--create the paging bar--
$PagingBar='';
while($StartPage<=$EndPage)
{
if($Page==$StartPage) {
	$PagingBar=$PagingBar . $StartPage . '';
}
else {
	$PagingBar=$PagingBar . '
	<a href="test.php?page=' . $StartPage . '">' . $StartPage . '</a>
	';
}
$StartPage++;
}

//---show the paging bar--
echo $PagingBar;
echo '</html>';
?>

Link to comment
https://forums.phpfreaks.com/topic/261437-result-paging/
Share on other sites

Finally Figured it out. Thanks anyway. Just wanted to post solution for others..

 

<?php
echo '<html>';
$Page=$_GET["page"]; //the page number requested
$AvailablePages=5; //number of pages available after the page requested
//---calculations---
$StartPage=round($Page/3)*3-2;
if($StartPage<2) { $StartPage=1; }
$EndPage=$StartPage+$AvailablePages-1; //the last page number to be displayed in paging

//--create the paging bar--
$PagingBar='';
while($StartPage<=$EndPage)
{
if($Page==$StartPage) {
	$PagingBar=$PagingBar . $StartPage . '';
}
else {
	$PagingBar=$PagingBar . '
	<a href="test.php?page=' . $StartPage . '">' . $StartPage . '</a>
	';
}
$StartPage++;
}

//---show the paging bar--
echo $PagingBar;
echo '</html>';
?>

Link to comment
https://forums.phpfreaks.com/topic/261437-result-paging/#findComment-1339703
Share on other sites

Thank you for coming back and posting the answer.  The boards tend to get low traffic on the weekends.

 

Next time your thread is solved, you can click the "mark solved" button along the top or bottom to mark it as such.  I've already marked this one for you.

 

Come back if you need more help!

Link to comment
https://forums.phpfreaks.com/topic/261437-result-paging/#findComment-1339704
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.