#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    Basically, i am using file() and a for loop to display content from text files, but i don't want to have all the information displayed at the same time.

    I want to show the first 20 lines, then have a link saying "Click for the next 20 entries" which takes the user to the next page which has the next 20 lines. What is the simplest way to do this?

    Thanks
    Jamie

    ------------------
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    This should work. untested...
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    if(isset($next_submit) && $page*20 < $total) { $page+=1; }
    if(isset($prev_submit) && $page > 0) { $page -=1; }
    if(!isset($page)) { $page = 0; }

    $file = file("filename.txt");
    $total = count($file);
    $start = 20 * $page;
    $finish = $start + 20;

    for($count=$start;$count<$finish;$count++)
    {
    echo $file[$count] . "<BR>n";
    }
    echo "<form method=post action=$PHP_SELF>n";
    echo "<input type=submit name=prev_submit value="<<Prev" >n";
    echo "<input type=submit name=next_submit value="Next>>" >n";
    echo "<input type=hidden name=page value=$page>n";
    echo "<input type=hidden name=total value=$total>n";
    echo "</form>n";
    ?>
    [/code]

    You can use cookies or sessions for the $page and $total. I don't like cookies, so I just use hidden form elements.

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    Hmm...re-read your question. If you really want a link, you'll have to do something like this. Use these links instead of the form at the end of what I said.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    if($page !=0)
    {
    echo "<a href="$PHP_SELF?page=$page&total=$total&prev_submit=1">Previous 20 Lines</a>n";
    }
    if((20*$page) < $total)
    {
    echo "<a href="$PHP_SELF?page=$page&total=$total&next_submit=1">Next 20 Lines</a>n";
    }
    ?>
    [/code]

    You can add the if statements in for the form also, deciding whether or not to show the button.

    ---John Holmes...

IMN logo majestic logo threadwatch logo seochat tools logo