TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack (1) Thread Tools Search this Thread Display Modes
Old 09-08-2007, 05:43 AM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default Pagination Or Something Else?

So I am making a portfolio, and it will have a page with photography and a page with web design/graphic work, I only want to show 4 images (previews) a page and it will have a link saying like Full View and it will show you a full view of the image using lightbox 2.0. I was wondering should i use pagination or something, and if i should use pagination if somebody could help me make a script for it, i read the tutorial here but it didnt make any sense to me..

I have a page with the information up already at
http://www.randycram.com/photography.php

can anybody tell me how i would go about doing this? i want a link like
"Previous - 1 2 3 4 5 etc.. - Next" at the bottom and each page will display 4 images.

Note: etc being numbers past 5.
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 09-08-2007, 10:27 AM   #2 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

Heres a function a wrote a while ago, isnt the best coding but it produces some very nice results, including google like pagination!

PHP Code:
    function pagination($current_page$num_of_pages)
    {
            
            if(
$current_page $num_of_pages)
                
$current_page $num_of_pages;
                
            if(
$current_page == "")
                
$current_page 1;
            
            if(
$current_page != 1)
                
$prev $current_page 1;
                
            if(
$current_page != $num_of_pages)
                
$next $current_page 1;
            
            
$min $current_page-5;
            
$max $current_page+5;
            if(
$min 1)
                
$min 1;
            if(
$current_page && $num_of_pages 10)
                
$max $num_of_pages;
            elseif(
$current_page && $current_page 10)
                
$max 10;
                
            if(
$max $num_of_pages)
                
$max $num_of_pages;
                
            if(
$prev)
                
$pagination[] = "P-".$prev;
            
            for(
$i=$min$i <= $max$i++)
            {
                
$pagination[] = $i;
            }
            
            if(
$next)
                
$pagination[] = "N-".$next;
            return 
$pagination;
    } 
Usage:
I wrote the class to be standalone, thus it is a little different than if it was written within a script:
PHP Code:
$iNumPerPage 25;
$iNumResults  200//number of results
$iNumPages    ceil($iNumResults/$iNumPerPage);

if(
$_REQUEST['iPage'] < 1)
   
$iPage 1//Page number
$aPages pagination($iPage$iNumPages);

print_r($aPages);
/* Outputs
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => N-2
)
*/ 
As you can see it produces some weird results....

If you want to parse the array, ive used code like:
PHP Code:
        foreach($aPages as $page)
        {
                if (
stripos($page"p-") !== false)
                {
                        
$p substr($page, -1);
                        if(
$p != 1)
                            print 
"<a href='/".$p."/".urlencode($search)."'>Prev</a>";
                        else
                           print 
"<a href='/'>Prev</a>";
                }
                elseif(
stripos($page"n-") !== false)
                {
                        
$p substr($page, -1);
                        if(
$p != 1)
                            print 
"<a href='/".$p."/".urlencode($search)."'>Next</a>";
                        else
                            print 
"<a href='/'>Next</a>";
                }
                else
                {
                    if(
$page != 1)
                        print 
"<a href='/".$page."/".urlencode($search)."'>".$page."</a>";
                  else
                        print 
"<a href='/".urlencode($search)."'>".$page."</a>";                 
                }
        } 
Anywho, like i said before this isnt my best code, but it does work :)
bluesaga is offline  
Reply With Quote
Old 09-14-2007, 01:44 PM   #3 (permalink)
The Contributor
 
Shaun's Avatar
 
Join Date: Sep 2007
Posts: 41
Thanks: 0
Shaun is on a distinguished road
Default

I know this isnt really pagination, but for one script i made the following:
PHP Code:
        <h2>Mailing List Users</h2>
        <table>
            <tr class="head">
                <td><b>Name</b></td>
                <td><b>Email</b></td>
                <td><b>Postcode</b></td>
                <td><b>Genres</b></td>
                <td></td>
            </tr>
        <?php
            $page 
$_GET['page'];
            if (isset(
$page))
            {
                if ( 
$page == '1' )
                {
                    
$limit "20, 20";
                } else
                {
                    
$start $page*20;
                    
$limit $start ", 20";
                }
            } else
            {
                
$limit "0, 20";
            }
            
$data  Sql::query("SELECT * from mailing_list order by newsletterID ASC limit "$limit);
            while(
$newsletter mysql_fetch_array($data))
            {
                echo 
"<tr>\n";
                echo 
"    <td>" .$newsletter['firstname']. " " .$newsletter['lastname']. "</td>\n";
                echo 
"    <td>" .$newsletter['email']. "</td>\n";
                echo 
"    <td>" .$newsletter['postcode']. "</td>\n";
                echo 
"    <td>" .$newsletter['genres']. "</td>\n";
                echo 
"    <td><a href='mailing_list.php?edit=" .$newsletter['newsletterID']. "'>(edit)</a> <a href='links.php?delete=" .$newsletter['newsletterID']. "'>(delete)</a></td>\n";
                echo 
"</tr>\n";
                
$last++;
            }
        
?>
        </table>
        <?php
        
        $result   
Sql::query("SELECT * from mailing_list order by newsletterID");
        
$num_rows mysql_num_rows($result);
        if ( 
$num_rows 20 )
        {    
            if (!
$page == "0" )
            {
                
$prev $page-1;
                if (
$page == "1" )
                {
                    echo 
"<a href='mailing_list.php'>< Prev</a> ";
                } else
                {
                    echo 
"<a href='mailing_list.php?page=".$prev."'>< Prev</a> ";
                }
            }
            
$calc $page*20+20;
            if ( 
$num_rows $calc )
            {
                
$next $page+1;
                echo 
"<a href='mailing_list.php?page=".$next."'>Next ></a>";
            }
        }
        
$results explode(","$limit);
        if ( 
$results[0] == "0" )
        {
            
$results[0] = 1;
        }
        if ( !
$page == "0" )
        {
            if ( 
$page == "1" )
            {
                
$last $last+20;
            } else
            {
                
$last $page*20+$results[1];
            }
        }
        echo 
"<p>Showing Results: " $results[0] . " to " $last ." of " $num_rows "</p>";
    }
        
?>
To me it seems like a lot of code for something thats only changing the page to show the next 20 results.

Any hints of doing this better?
Send a message via MSN to Shaun Send a message via Skype™ to Shaun
Shaun is offline  
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/general/1054-pagination-something-else.html
Posted By For Type Date
Yahoo! Answers - PHP & MYSQL doubt? This thread Refback 01-05-2008 04:39 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB 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 06:45 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design