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 Thread Tools Search this Thread Display Modes
Old 04-20-2008, 10:35 PM   #1 (permalink)
The Wanderer
 
blayne4k's Avatar
 
Join Date: Apr 2008
Location: Trapped in my own little world.
Posts: 14
Thanks: 0
blayne4k is on a distinguished road
Default Arrays + Pages

Here is a script that converts arrays into pages, very customizable.

PHP Code:
<?PHP
//array paging system
//how many do you want per page?
$perpage 30;

//query to make the array, here im doing a query to select all the users
$query mysql_query("SELECT * FROM users");
while(
$row=mysql_fetch_assoc($query)) {
    
//set all users in an array
    
$users[] = '<a href="'.$row[homepage].'">'.$row[username].'</a>';
}

//I need the total amount of rows I have
$total mysql_num_rows($query);

/*
    how many pages are there?
    $pages = $total / $perpage
    thats "about" how many pages but if there are 323 users then we have:
    323 / 30 = 10.7666667
    so we obviously need to make that 11 not 10 so...
    this gets the number 10.76 and adds 1 to it, so its 11.76, then explodes it so [0] = 11; and [1] = 76; and 11 is the amount of pages we want.
*/
$pages explode('.', (($total/$perpage)+1));
$pages $pages[0];

//I need to find out what page im on
$pageid ereg_replace('[^0-9]'''$_GET['pageid']);
//if page is not set it needs to be one
if($pageid=='') { $pageid 1; }

//so if pageid = 1, we need to display the array numbers 0-29, pageid 2 would be 30-59 and so on..
$start = ($pageid $perpage)-$perpage// (1*30)-30=0; (2*30)-30=30;
$end $start + ($perpage 1);    // 0 + (30-1) = 29; 30+(30-1)=59;

//echo the output
while ($start <= $end) {
    echo 
$users[$start] . '<br>';
    
$start++;
}

//what about pages?
$i 1;
//do a while loop from 1 to how many pages you want
while($i <= $pages) {
    if(
$i == $pageid) {
        
//if this page is the page your on you wont wanna link it again cause there already on that page
        
$pagess .= ' ['.$i.'] ';
    } else {
        
$pagess .= ' <a href="?pageid='.$i.'">['.$i.']</a> ';
    }
    
$i++;
}
echo 
$pagess;
?>
This actual script is untested but the concept I used on an old project.

Last edited by blayne4k : 04-21-2008 at 01:03 AM. Reason: Need to echo pages..
blayne4k is offline  
Reply With Quote
The Following User Says Thank You to blayne4k For This Useful Post:
Wildhoney (04-21-2008)
Reply



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 05:12 AM.

 
     

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