RicardoC is right, you need to use the explode and count function. Here's what you need to do.
For this example, we're going to pretend it's a tutorial beign split up into multiple pages. Our tutorial content is called tutorial in the table and our bbcode for a new page is called [nextpage].
Say you're using the $_GET for the id of the tutorial, you'll also need to know what page number the user has requested, you'll do this with the following:
if( !isset( $_GET['page'] ) ){
$no = 1;
}else{
$no = (int)$_GET['page'];
}
So if the url is the following, domain.com/tutorials.php?id=1, then the $_GET['page'] would not be set, so the $no is 1, otherwise it is set, ?id=1&page=2, $no would be 2.
Next step, you get all the tutorial information. You'll then need the following.
$tutorial = explode( '[nextpage]', $r['tutorial'] );
$r['tutorial'] is the tutorial content, [nextpage] is the bbcode to split the tutorial up. What this does is put the tutorial into an array which we've put into $tutorial, say you've got 3 page, the array would be the following:
$tutorial['0'] for page 1, ['1'] for page 2, ['2'] for page 3.
$num = count( $tutorial );
How many pages do we have? We count the number of values we have in the array.
if( $num > 1 ){
If there is more than one page.
$i = 0;
while( $i <= $num ){
if( $i == $no ){
print ' <a class="inactive-no">'. $i .'</a>';
}else{
print ' <a href="domain.com/tutorial.php?id=1&no='. $i .'">'. $i .'</a> ';
}
$i++;
}
This shows the pagination.
To show the relevant page, you use the following
$tutorial[$no - 1]
Because an array starts with 0, and our $no would start with 1, as with page 1, or page 2, we need to decrease it by 1.
You can enhance this code a lot more to suit you're needs, enhance the pagination with style and add a previous and next link (real easy to do).
If you need more help on this, then I can write a full tutorial on it all.