Jump to content

pagination numbering pattern


deepson2

Recommended Posts

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

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?

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?

Archived

This topic is now archived and is closed to further replies.

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