pagination


#1

Hi I’m trying to have break long pages into smaller pages and have nav to prev next and pages inbetween like “PREV 1 2 3 4 5 NEXT”

I have managed to get it working well sorta the PREV & NEXT work great and they don’t display if on the first/last page.

The problem am having is am not sure how to go about making links to other pages between the prev and next links like 1 2 3 4 5.

I am breaking the pages using [pagebreak] the pages i want breaking down into smaller pages are from a single record/ID not multiple records so most tutorials i’ve found are explaining something useful just not for what am trying to do.

Can anyone help me with this?

here’s my code:

<div id="center">
<?php
//Content

//if no page specified, default to the first page ($page =0)
if (!isset($_GET['page'])) {
$page = 0;
} else {
$page = $_GET['page'];
}
//split the text into an array of pages
$textarray = spliti('[PAGEBREAK]', $thearticle);

//select the page we want
$thearticle = $textarray[$page];

$PHP_SELF = $_SERVER['PHP_SELF'];
$ID = $_GET['ID'];
//actual content
?>
<p>
<?php
//prev page
if ($page != 0) {
	$prevpage = $page - 1;
	echo "<a href="$PHP_SELF?ID=$ID&amp;page=$prevpage">". 'Previous</a>';
	echo " | ";
	}
 
// next page	
if ($page < count($textarray) - 1) {
	$nextpage = $page + 1;
	echo "<a href="$PHP_SELF?ID=$ID&amp;page=$nextpage">" . 'Next</a>';
	}
	?>
	<br /><a href="index.php">Back to front page</a></p>
<?php 
//conent
echo "<h1>$title</h1>";
echo $thearticle;

	if(isset($_GET['ID']))
	{	
	}
			
	$i ++;
	
	}	?>
<p>
<?php
//prev page
if ($page != 0) {
	$prevpage = $page - 1;
	echo "<a href="$PHP_SELF?ID=$ID&amp;page=$prevpage">". 'Previous</a>';
	echo " | ";
	}

 
// next page	
if ($page < count($textarray) - 1) {
	$nextpage = $page + 1;
	echo "<a href="$PHP_SELF?ID=$ID&amp;page=$nextpage">" . 'Next</a>';
	}
	?>
	<br /><a href="index.php">Back to front page</a></p>

</div><!-- close center -->

Thanks in advance


#2

What you’re going to have to find out (in the PHP script) is how many pages in total there will be. This isn’t hard, but the method depends on the external source that holds whatever you want split up over multiple pages. From there on, it’s as easy as a for loop :wink: