CodeTech Posted April 22, 2012 Share Posted April 22, 2012 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/261437-result-paging/ Share on other sites More sharing options...
CodeTech Posted April 22, 2012 Author Share Posted April 22, 2012 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/261437-result-paging/#findComment-1339703 Share on other sites More sharing options...
ManiacDan Posted April 22, 2012 Share Posted April 22, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/261437-result-paging/#findComment-1339704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.