SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to paginate an article/news in php?

    hi all,

    I want to paginate an article/new, that contains more than one page of content. I don't want to scroll down till end.

    I want to check the length of the article and divide it into multiple pages and display at bottom of the page as next page links....

    give me some idea about it.
    Thanking you all...

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Split the content across multiple pages, and place "prev page" and "next page" links along the top and bottom of the content. It's not that difficult.

    Or, are you looking for an automatic way for it to be done for you?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this:
    PHP Code:
    <?php

    $pageNum 
    = isset($_GET['page']) ? (int) $_GET['page'] : 0;

    $self $_SERVER['PHP_SELF'];

    // get the text from the file or form mysql database 
    $string file_get_contents("D:\test.txt");

    // quantity to display 
    $length 3000;

    // string length 
    $string_length strlen($string);

    // page number or quantity 
    $start $pageNum $length;

    $endif $string_length $start;

    // Returns the portion of string specified by the start and length parameters 
    $msg substr($string$start$length);

    echo 
    wordwrap($msg100"\n");

    echo 
    "\n<br />------<br />\n";

    if (
    $pageNum 0)
    {
        
    $page $pageNum 1;
        
        echo 
    '<br/><a href="' $self '?page=' $page '">prev page</a>';
    }

    if ((
    $string_length $length) and ($endif $length))
    {
        
    $page $pageNum 1;
        
        echo 
    '&nbsp;<a href="' $self '?page=' $page '">next page</a>';
    }
    my mobile portal
    ghiris.ro

  4. #4
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Thanking you for your reply..pmw57.

    How to automate this functionality..?

    give me an example to understand...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •