View Single Post
Old 04-16-2009, 04:59 PM   #3 (permalink)
allworknoplay
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
First off, why are you posting this in Script Giveaways if you need help with it?
Yeah, I figured I would share what I have so far. I suppose I should have waited until the code is 100% complete to my liking.

Quote:
Originally Posted by Tanax View Post
Secondly, I see you still base your entire function on a database - which is fine - but not really good practice.
Well I think this is POV, I'd like to get suggestions from others. I know good practice is to be as general as possible with the data so you can insert any type, (arrays, SQL, files/directories etc..) But you also have to remember I am a newbie...

Quote:
Originally Posted by Tanax View Post
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.


Thank you! I think I can figure it out now with "$span".
Let me get back to the grind and hopefully figure it out at some point today...
allworknoplay is offline  
Reply With Quote