First off, why are you posting this in Script Giveaways if you need help with it?
Secondly, I see you still base your entire function on a database - which is fine - but not really good practice.
About your issue, you have to insert a new variable $span, and do some simple math logic to get around this. I would post my updated script, but it's entirely OOP so I'm not sure if that would actually do any help.
But like I said, you need to do some simple math.
Bascicly, what you wanna check for is if the pagenr(in your for-loop) is outside the span, and only display those who are in the span. By span, I mean the value of the variable $span, which would be an integer - corresponding to how many pages you want on each side of the current page.
Example: $span = 2
3 4
5 6 7
$span = 4
1 2 3 4
5 6 7 8 9
Here's the code to display the first link if the you're outside the span and above first page.
PHP Code:
// If the current page minus the span is larger than 1, it means that the first page is outside the span, and thus we want to
// display it!
if(($page[0] - $span) > 1) {
echo '<a href="?page=1">First</a> ';
// If the current page minus (span + 1) is larger than 1, it means that the first page is outside the span AND it is outside the
// span with more than 1, and thus we want to add an extra ".." after the first link.
if(($page[0] - ($span + 1)) > 1) {
$firstlink .= '.. ';
}
}
$page[0] is the current pagenr.