Pro.Luv Posted December 19, 2008 Share Posted December 19, 2008 Hi, I have this code that I need help with its something like a pagination: <? $pages = 20; $limit = 10; $count = 0; if (strlen($_GET["pgnum"]) == 0 OR $_GET["pgnum"] == 1){$disablePrevious = "disabled"; } else { $disablePrevious = ""; } $nextpagePrevious = $_GET["pgnum"] - 1; print "<a href=\"$PHP_SELF?offset=$limit&pgnum=$nextpagePrevious&pages=$pages\" style=\"text-decoration:none\" <input type=\"button\" value=\"< Previous\" $disablePrevious></a> "; for ($i=1;$i<=$pages;$i++) { $newoffset=$limit*($i-1); $cpgnum = $i; if ($pages > 1) { //REMOVE TO PRINT 20 links if ($count == $limit){ print "... "; break; } if ($_GET["pgnum"] == $cpgnum){ print "<a href=\"$PHP_SELF?offset=$newoffset&pgnum=$cpgnum&pages=$pages\"><b>$cpgnum</b></a> | "; } else { print "<a href=\"$PHP_SELF?offset=$newoffset&pgnum=$cpgnum&pages=$pages\">$cpgnum</a> | "; } } $count++; } if ($_GET["pgnum"] AND $_GET["pgnum"] == $_GET["pages"]){$disableNext = "disabled";} else{$disableNext = "";} $nextpage = $_GET["pgnum"] + 1; print "<a href=\"$PHP_SELF?offset=$limit&pgnum=$nextpage&pages=$pages\" style=\"text-decoration:none\"><input type=\"button\" value=\"Next >\" $disableNext></a>"; ?> what this code basically does is print out 10 links this code: if ($count == $limit){ print "... "; break; } checks if $count is equal to limit and at the top you see $limit is set to 10.. so it only prints out 10 links if you remove the code above it will print 20 links.. I want to only show 10 links then when the 10th link is shown I want show the 11th link then 12th like before 10th link is reached: 1,2,3,4,5,6,7,8,9,10 after 10th link is reached 2,3,4,5,6,7,8,9,10,11 and so on.. The 1 goes away and the 11th link shows. Really need help with this! thanks Link to comment https://forums.phpfreaks.com/topic/137699-pagination/ Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 If I am looking at this correctly I think it may be an issue with your $count variable. You set it as 0 and then you compare it to the limit but you never change it anywhere so it is always going to be 0. Please correct me if I am wrong. Link to comment https://forums.phpfreaks.com/topic/137699-pagination/#findComment-719743 Share on other sites More sharing options...
Pro.Luv Posted December 19, 2008 Author Share Posted December 19, 2008 hi ngreenwood6, it is counting if you check: if ($_GET["pgnum"] == $cpgnum){ print "<a href=\"$PHP_SELF?offset=$newoffset&pgnum=$cpgnum&pages=$pages\" $active $active1><b>$cpgnum</b></a> | "; } else { print "<a href=\"$PHP_SELF?offset=$newoffset&pgnum=$cpgnum&pages=$pages\" $active $active1>$cpgnum</a> | "; } } //COUNTING HERE $count++; Link to comment https://forums.phpfreaks.com/topic/137699-pagination/#findComment-719750 Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 nevermind that comment that was wrong. what happens if you change this: //REMOVE TO PRINT 20 links if ($count == $limit){ print "... "; break; } to this: //REMOVE TO PRINT 20 links if ($limit == 10){ print "... "; break; } Just to make sure that is working. Link to comment https://forums.phpfreaks.com/topic/137699-pagination/#findComment-719754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.