deepson2 Posted December 2, 2009 Share Posted December 2, 2009 Hello, I have following code which works great for pagination. but i have small issue now. Now the output is coming like this mypage.php?page=2 I want it like this mypage.php/2 code- $numrows = 100; //$numrows = $row['numrows']; //echo "$row[numrows]"; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); echo "$maxPage"; $self = 'mypage.php'; // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one $Nav=""; If($pageNum > 1) { $Nav .= "<a class='nav' href=\"$self?page=" . ($pageNum-1) . " \"><< Prev</a>"; } /*For($i = 1 ; $i <= $maxPage ; $i++) { If($i == $pageNum) { $Nav .= "<b>$i</b>"; }Else{ $Nav .= "<a class='nav' href=\"$self?page=" . $i . "\">$i</a>"; } }*/ If($i == $pageNum) { $Nav .= "<p class='page'>1</p>"; } Else { $page1=$pageNum-1; if($page1==0){} else { $Nav .= "<p class='pagination'><a href=\"$self?page=" . $page1. "\">$page1</a></p>"; } $Nav .= "<p class='page'>$pageNum</p>"; $page2=$pageNum+1; if($page2<=$maxPage) { $Nav .= "<p class='pagination'><a href=\"$self?page=" . $page2. "\">$page2</a></p>"; } else{ } } If($pageNum < $maxPage) { $Nav .= "<a class='nav' href=\"$self?page=" . ($pageNum+1) . "\">Next >></a>"; } Echo "<br><br>" . $Nav; /* for showing all rows $Nav=""; If($pageNum > 1) { $Nav .= "<a class='nav' href=\"$self?page=" . ($pageNum-1) . " \"><< Prev</a>"; } For($i = 1 ; $i <= $maxPage ; $i++) { If($i == $pageNum) { $Nav .= "<b>$i</b>"; }Else{ $Nav .= "<a class='nav' href=\"$self?page=" . $i . "\">$i</a>"; } } If($pageNum < $maxPage) { $Nav .= "<a class='nav' href=\"$self?page=" . ($pageNum+1) . "\">Next >></a>"; } Echo "<br><br>" . $Nav; */ /*$Nav=""; if ($pageNum > 1) { $page = $pageNum - 1; $Nav = " <a href=\"$self?page=$page\">|Prev|</a> "; $Nav = " <a href=\"$self?page=1\">|<<</a> "; //echo "$first"; } else { $Nav = ' |Prev| '; // we're on page one, don't enable 'previous' link $Nav = ' |<< '; // nor 'first page' link } // print 'next' link only if we're not // on the last page echo "$pageNum"; if ($pageNum < $maxPage) { $page = $pageNum + 1; $Nav = " <a href=\"$self?page=$page\">|Next|</a> "; $Nav = " <a href=\"$self?page=$maxPage\">>>|</a> "; } else { $Nav = ' |Next| '; // we're on the last page, don't enable 'next' link $Nav = ' >>| '; // nor 'last page' link } Echo "<br><br>" . $Nav;*/ can anyone please tell me how can i achieve that? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/ Share on other sites More sharing options...
deepson2 Posted December 2, 2009 Author Share Posted December 2, 2009 Any help?? Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-969590 Share on other sites More sharing options...
trq Posted December 2, 2009 Share Posted December 2, 2009 Replace all instances of page= with / Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-969609 Share on other sites More sharing options...
deepson2 Posted December 2, 2009 Author Share Posted December 2, 2009 Thanks for yorr reply thrope I replaced that. So now i can see the following link in the address bar mypage.php?/2 needless to say that its not working. here is my .htaccess look like RewriteRule mypage/([^/]+) /mypage/$1/[NC] RewriteRule mypage.php/([^/]+) /mypage/$1/[NC] Can anyone tell me how can i remove "?" from my url and how could make it work as well? Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-969692 Share on other sites More sharing options...
deepson2 Posted December 3, 2009 Author Share Posted December 3, 2009 Any help?? Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-970259 Share on other sites More sharing options...
trq Posted December 3, 2009 Share Posted December 3, 2009 RewriteRule mypage/([^/]+) /mypage.php?page=$1[NC] Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-970265 Share on other sites More sharing options...
deepson2 Posted December 3, 2009 Author Share Posted December 3, 2009 php code $numrows = 100; //$numrows = $row['numrows']; //echo "$row[numrows]"; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); echo "$maxPage"; $self = 'mypage'; // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one $Nav=""; If($pageNum > 1){ $Nav .= "<a class='nav' href=\"$self/" . ($pageNum-1) . " \"><< Prev</a>"; } /*For($i = 1 ; $i <= $maxPage ; $i++) { If($i == $pageNum) { $Nav .= "<b>$i</b>"; }Else{ $Nav .= "<a class='nav' href=\"$self/" . $i . "\">$i</a>"; } }*/ If($i == $pageNum) { $Nav .= "<p class='page'>1</p>"; } Else { $page1=$pageNum-1; if($page1==0){} else { $Nav .= "<p class='pagination'><a href=\"$self/" . $page1. "\">$page1</a></p>"; echo $Nav; } $Nav .= "<p class='page'>$pageNum</p>"; $page2=$pageNum+1; if($page2<=$maxPage) { $Nav .= "<p class='pagination'><a href=\"$self/" . $page2. "\">$page2</a></p>"; } else{ } } If($pageNum < $maxPage) { $Nav .= "<a class='nav' href=\"$self/" . ($pageNum+1) . "\">Next >></a>"; } Echo "<br><br>" . $Nav; /* for showing all rows $Nav=""; If($pageNum > 1) { $Nav .= "<a class='nav' href=\"$self/" . ($pageNum-1) . " \"><< Prev</a>"; } For($i = 1 ; $i <= $maxPage ; $i++) { If($i == $pageNum) { $Nav .= "<b>$i</b>"; }Else{ $Nav .= "<a class='nav' href=\"$self/" . $i . "\">$i</a>"; } } If($pageNum < $maxPage) { $Nav .= "<a class='nav' href=\"$self/" . ($pageNum+1) . "\">Next >></a>"; } Echo "<br><br>" . $Nav; */ /*$Nav=""; if ($pageNum > 1) { $page = $pageNum - 1; $Nav = " <a href=\"$self/$page\">|Prev|</a> "; $Nav = " <a href=\"$self/1\">|<<</a> "; //echo "$first"; } else { $Nav = ' |Prev| '; // we're on page one, don't enable 'previous' link $Nav = ' |<< '; // nor 'first page' link } // print 'next' link only if we're not // on the last page echo "$pageNum"; if ($pageNum < $maxPage) { $page = $pageNum + 1; $Nav = " <a href=\"$self/$page\">|Next|</a> "; $Nav = " <a href=\"$self/$maxPage\">>>|</a> "; } else { $Nav = ' |Next| '; // we're on the last page, don't enable 'next' link $Nav = ' >>| '; // nor 'last page' link } Echo "<br><br>" . $Nav;*/ And RewriteRule mypage/([^/]+) /mypage.php?page=$1[NC] Still no luck with this code. i am nor getting 2nd page. what can i do any suggestion? Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-970284 Share on other sites More sharing options...
deepson2 Posted December 4, 2009 Author Share Posted December 4, 2009 What i need to change here so my pagination works with only numbers. I just don't understand why my" $self/" is not working? Any idea or suggestion please? Link to comment https://forums.phpfreaks.com/topic/183690-pagination-numbering-pattern/#findComment-970988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.