Page number navigation [1] [2] [3] [4]

sitemaniac

New Member
Hi,

I'm developing a site that will have numerous spill over pages i.e as it grows the main page will need to be split into page [2] [3] ... [100] etc

So down the bottom I will have a sort of index of the page numbers as above [1] [2] [3] ... [100]

The way I'm doing it at the moment is literally doing it with html and links at the bottom of each page. I want the page I am currently on to be not a link but just a plain e.g [20] with all the ones around it to be links.

I'm starting to realise this is not future proof and when I am on page 100 I wll have to go back and add in the extra links to each other page.

I think I will have to do a php includes so I can change them all at one.

But this way the links will all be the same and the page I am currently on will be a link also.

Plus, When the pages numbers are too many to display in a row it's common to see something like this
[FIRST PAGE].. [51] [52] [53] [54] [55] [56] [57] [58] .. [LAST PAGE]

Does anyone know how this system is done with html, css, php includes?

Is there an easy way of doing this?


Any help would be much appreciated. I hope there's an easy method for achieving this!
Thanks.
 

leroy30

New Member
Where are you getting the content from? If you are pulling it frame a database then you should be generating those links dynamically.

I develop in ASP.net so I'm not much help in the PHP realm but do a search for pagination :)
 

notarypublic

New Member
I had to do a similar thing, a few months ago. If I can find the code, I'll post it here. It was a bugger to figure out!

Edit: Huh. There it was. Now if anyone can explain how it works, I'll make them strawberry-topped pastries.

HTML:
<?php
if ( isset( $_GET["query"] ) && trim( $_GET["query"] ) != "" && mysql_num_rows( $result ) > 15 )
{   
    print "<p>page: ";

    // Assume we're starting on page 1
    if ( ! isset( $_GET["page"] ) || ! is_numeric( $_GET["page"] ) || $_GET["page"] < 1 || $_GET["page"] > ceil( mysql_num_rows( $result ) / 15 ) )
        $_GET["page"] = 1;

    $bottom_limit = $_GET["page"] - 5;
    $top_limit = $_GET["page"] + 5;

    // Check for the bottom limit
    if ( max( $_GET["page"] - 5, 1 ) == 1 )
    {
        $bottom_limit = 1;
        $top_limit = 11;
    }

    // Check for the top limit
    if ( min( $_GET["page"] + 5, ceil( mysql_num_rows( $result ) / 15 ) ) == ceil( mysql_num_rows( $result ) / 15 ) )
    {
        $bottom_limit = ceil( mysql_num_rows( $result ) / 15 ) - 10;
        $top_limit = ceil( mysql_num_rows( $result ) / 15 );
    }

    for ( $i = $bottom_limit; $i <= $top_limit; $i++ )
        /*for ( $i = max( $_GET["page"] - 5, 1 ); $i <= min( ceil( mysql_num_rows( $result ) / 15 ), $_GET["page"] + 5 ); $i++ )*/
        /*    for ( $i = 1; $i <= ceil( mysql_num_rows( $result ) / 15 ); $i++ )*/
    {   
        if ( $i == $_GET["page"] || $i == 1 && $_GET["page"] == "" )
        {   
            print "<strong>$i</strong> ";
        }   
        else
        {   
            $query_string = urlencode( $_GET["query"] );
            print "<a href = \"juego.php?query={$query_string}&amp;page={$i}\">{$i}</a> ";
        }   
    }   
    print "</p>\n";
}
?>
 
Last edited:

sitemaniac

New Member
Thanks for posting that. I'll have a go at trying to integrate it later. Looks head wrecking already :D

thanks again!
 
Last edited:

sitemaniac

New Member
Ok, I could do with some help with this. I've coped and pasted the above code into my homepage (above the footer). Nothing shows up. How do I make it work?


:(
 
Top