Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-06-2009, 09:48 PM Pagination script
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
I need a simple pagination script.

I have a file with about 300 words, I need the put to be seperated into multiple page, each page will show a limited amount of words.

I want to have a navbar at the top with how many pages I can go go back to and forward to.

Thank You.

I would also like this in a flat file please.
No database connection.

I can do payment as in FREE hosting or a proffessional logo in photoshop.
sith717 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-06-2009, 10:26 PM Re: Pagination script
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
This should retrieve the paginated text from a file dynamically:

PHP Code:
function getContent($page$wordCount$filePath, &$error)
{
     
$start = ($page 1) * $wordCount;

     
//read in text
     
$content = @file_get_contents($filePath);
     if(!
$content)
     {
          
$error 'Bad file path';
          return 
false;
     }

     
$contentArr explode(' '$content); //array of words
     
$content '';
     
$words count($contentArr);

     for(
$i $start$i < ($start $wordCount); $i++)
     {
          if(
$start >= $words)
          {
               
$error 'Page out of range';
               return 
false;
          }

          if(
$i >= $words)
          {
               
$i $start $wordCount;
          }
          else
          {
              
$content .= $contentArr[$i] . ' ';
          }
     }

     return 
$content;
}

//assuming page number is URL encoded
$page = isset($_GET['page']) ? $_GET['page'];
$filePath 'path/to/file.txt';

//number of words to retrieve
$words 100;

$errorMsg false//will store any error message from the function
$content getContent($page$words$filePath$errorMsg); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 08-06-2009 at 10:48 PM.. Reason: bug
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Pagination script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.81806 seconds with 12 queries