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
Old 10-18-2012, 01:00 PM   #4 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
dashixiong is offline  
Reply With Quote
Old 10-22-2012, 09:32 AM   #5 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong 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 05: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 11:16 PM.

 
     

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