Jump to content

Pagination: $X > 0 and $X <= $totalpages


Recommended Posts

Pgination value for $X = 1 is:

 

first, -2, -1, 0, [1], 2, 3, 4, last

 

Pagination value for $x = $total_pages

first, 34, 35, 36, [37], 38, 39, 40, last

 

Note: I have 37 pages.

 

<?php
$range = 3;

for($x=($page - $range); $x < (($page + $range) + 1); $x++)
           {
   ?>
           <div style=' text-align: center; float:left; font-family: verdana; width: 20px; padding: 5px; margin: 1px; border-style:solid; border-width: 1px; border-color:#C8C8C8;'>
  <?php
	    echo ($x == $page) ? '<strong><a href="index.php?page='.$x.'"> '.$x.' </a></strong>' : '<a href="index.php?page='.$x.'"> '.$x.' </a> ';
  ?>
</div>
<?php
   }
?>

 

How to solve this problem?

Link to comment
https://forums.phpfreaks.com/topic/239714-pagination-x-0-and-x/
Share on other sites

Try this code.

 

<?php
$page = 1;
$total = 37;
$range = 3;

if ($page > 1) {
echo 'Previous ';	
}

for ($i = $page - $range; $i < $page + $range; $i++) {
if ($i > 0 and $i <= $total) {
	if ($i == $page) {
		echo "[$i] ";	
	} else {
		echo "$i ";
	}
}
}

if ($page < $total) {
echo 'Next';	
}
?>

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.