Jump to content

Recommended Posts

Hi all,

 

Anyone give me a few hints how I can add a next and previous button to my pagination links? I currently have this:

<?php
}
if($total_records > 5)
?>
<div id="pg">
<?php
{
for ($i = 1; $i <= $total_pages; $i++) {

echo "<a title='page $i' class='current' href='?catid=" . $catid ."&";
if($subid > 0)
{
echo "subid=";
echo $subid . "&";
}
echo "p= $i'>$i</a>";
}
}
?>

</div>

 

Which displays them nicely, but I would like a next and previous button.

 

Cheers

 

Link to comment
https://forums.phpfreaks.com/topic/218591-previousnext-pagination-links/
Share on other sites

Thanks again! The silly thing is I am already doing that for another part of the page  :(!!!

 

I am now using the below and still have a problem, $t is showing as the same as the page I am on ($p)

$t = $p-1;	
if($p > 1 )
{
echo "<a href=''?catid='" . $catid . "&";
	if($subid > 0)
	{
	echo "subid=";
	echo $subid . "&";
	echo "p=" . $t . "'><span class='disabled'>« Previous</span></a>";
	}
}

 

Just for clarification...

$t = the page you are viewing?

 

If this is the case do $t-1 for previous page link and $t+1 for next page link

 

Use the previous method of $total_pages to do the links between the next and prev.

 

Hopefully you get what I mean, if not just let me know :)

 

Regards, Paul.

Ohh right I see...

So if you are viewing page 10 $t=9 and $p-1=current page

Slightly confusing to me lol, but if you like I could re-write your current function and add next/prev links to it?

I'll comment so you know whats happening ect...

 

You could try using $p-2 = Prev and $p OR $p+1=Next

 

Tell me how it works out bud :)

 

Regards, Paul.

Well just to test I tried this out

<?php
$pagnat = 1;
$np = $p + $pagnat;
$nl = $p - $pagnat;
echo $np;
echo $nl;

{


if($p > 1 )
{
echo "<a href=''?catid='" . $catid . "&";
	if($subid > 0)
	{
	echo "subid=";
	echo $subid . "&";

	}
	echo "p=$nl'>« Previous</a> ";
}

for ($i = 1; 
$i <= $total_pages; $i++) 

{

echo "<a title='page $i' class='current' href='?catid=" . $catid ."&";
if($subid > 0)
{
echo "subid=";
echo $subid . "&";
}
echo "p=$i'>$i</a>  ";
}
}

if($p > 0 )
{
echo "<a href=''?catid='" . $catid . "&";
	if($subid > 0)
	{
	echo "subid=";
	echo $subid . "&";
	echo "p=";
	echo $np;
	echo "'> Next »</a> ";
	}
}

?>

 

Now $np and $nl echo out correctly when I just echo them, but when hovering on the next and prev buttons, they show the current page!

 

So when I am on p=2 $np=3 and $nl=1

 

How the hell is that working!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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