Andy11548 Posted February 6, 2012 Share Posted February 6, 2012 I've made a page which lists information from a database like: 1 Andy 2 James 3 Bob But if James over takes Andy it goes 1 James 2 Andy 3 Bob. I have that working. However, I've added multi pages into my website [1, 2, 3, 4, 5] etc, however, when you go onto a new page, it starts back at number 1. It doesn't continue adding 1 on. Does anyone know how to make this work? Thanks in advance, Andy. Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/ Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 need more info, code examples please Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1314924 Share on other sites More sharing options...
Andy11548 Posted February 6, 2012 Author Share Posted February 6, 2012 Right, i have a variable called $position = 1; Then I also have a while look like while($fetch = mysql_fetch_assoc($query)) { echo $position++.' '.$fetch['username']; } So if I had 4 usernames in the database with other values like cash it would be like: 1 Andy £100 2 Dan £98 3 Bob £23 4 James £10 etc, so it shows who has the highest amount of money. However, I've added that multi-page so that theres only 20 names per page. When I go onto a new page, insted of going 21 Name £ 22 Name £ 23 Name £ it goes 1 Name £ 2 Name £ 3 Name £ etc. I want the numbers to increase throughout the other pages. Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1314931 Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 you've got to pass that end position to the new page as it's start so on the link to move to the next age, add ?position=$position so that it will put whatever the current position is there, with your link code i can be more specific and then on the subsequent pages, you want to first make sure position isn't being set to 1, but also make sure it is being set to whatever the end position was so in the beginning <?php $position = $_GET['position']; ?> if all you need is the position, that's great. but if you need more info you may consider saving it to a session or a db. or passing a serialized array, which is my preferred quick and dirty method. Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1314944 Share on other sites More sharing options...
Andy11548 Posted February 6, 2012 Author Share Posted February 6, 2012 This didn't work, each time I clicked the next page, it would just keep upping the number :S Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1314947 Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 i'm sorry what exactly do you mean upping the number? can i see your next page link code?the foreach doesn't actually track the postition so instead of: while($fetch = mysql_fetch_assoc($query)){echo $position++.' '.$fetch['username'];} do: <?php $position = 1 ; while($fetch = mysql_fetch_assoc($query)){echo $position.' '.$fetch['username']; $position ++;} ?> that way position will actually keep track of the current position, rather than just echoing it. Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1314950 Share on other sites More sharing options...
Andy11548 Posted February 6, 2012 Author Share Posted February 6, 2012 Hello, heres my next page links // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&position=".$position."'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Last</a> "; } // end if Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1314955 Share on other sites More sharing options...
Andy11548 Posted February 6, 2012 Author Share Posted February 6, 2012 Still need this fixed :/ Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1315125 Share on other sites More sharing options...
PFMaBiSmAd Posted February 6, 2012 Share Posted February 6, 2012 You would take the page number and the number of records per page that your pagination script is using and calculate the starting number for any page. Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1315135 Share on other sites More sharing options...
PFMaBiSmAd Posted February 6, 2012 Share Posted February 6, 2012 Specifically - $position = (($currentpage-1)*$rowsperpage)+1; Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1315144 Share on other sites More sharing options...
Andy11548 Posted February 6, 2012 Author Share Posted February 6, 2012 Specifically - $position = (($currentpage-1)*$rowsperpage)+1; Thank you very very very much . Great help! Quote Link to comment https://forums.phpfreaks.com/topic/256505-muti-pages-1-2-3-with-counter/#findComment-1315207 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.