Jump to content

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


ebchost

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';	
}
?>

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.