Web Design Forum  
 
Go Back   Web Design Forum > Web and Graphic Design > Web Design

Reply
 
LinkBack Thread Tools Display Modes
Old 04-07-2011, 08:18 PM   #1
New Member
 
Join Date: Feb 2011
Posts: 13
Default Page number navigation [1] [2] [3] [4]

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.
sitemaniac is offline   Reply With Quote


Old 04-07-2011, 09:04 PM   #2
Gold Member
 
leroy30's Avatar
 
Join Date: Mar 2010
Location: Auckland, New Zealand
Posts: 326
Default

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
__________________
DVI web design | Portable Time Clock
leroy30 is offline   Reply With Quote
Old 04-08-2011, 07:32 PM   #3
Silver Member
 
notarypublic's Avatar
 
Join Date: Feb 2011
Posts: 191
Default

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 Code:
<?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";
}
?>
__________________
http://www.joshualoves.com/

Last edited by notarypublic; 04-08-2011 at 07:36 PM.
notarypublic is offline   Reply With Quote
Old 04-11-2011, 08:07 AM   #4
New Member
 
Join Date: Feb 2011
Posts: 13
Post

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

thanks again!

Last edited by sitemaniac; 04-15-2011 at 08:07 AM.
sitemaniac is offline   Reply With Quote
Old 04-15-2011, 08:08 AM   #5
New Member
 
Join Date: Feb 2011
Posts: 13
Default

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?


sitemaniac is offline   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:24 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.