SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast webmasts's Avatar
    Join Date
    Apr 2003
    Location
    usa
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Limiting number of links on a page

    Hi,

    I would like to allow visitors to add links on my page using the fopen() and fwrite() functio, storing the links on a text file and then displaying it on a webpage. I want to limit the number of links that can be allowed in a page. Let say I want 100 links on a page. If the links added goes over 100, then the old links goes to the next page. I want to keekp the NEW 100 links on the main page.

    How would you do it?

    Thanx

  2. #2
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this might work:

    use the readline() function
    PHP Code:
    <?php
    for ($i=$start$i $limit$i++) {
    $line readline ("Link: " );
    readline_add_history ($line);
    }

    print_r (readline_list_history());

    ?>
    the $start on the first page wold be zero and $limit would be 101.

    and when the first page is displayed...your link to the second page would make $start = $limit [previous one, i.e 101] and your $limit = $201

    and so on.

    The only thing I cannot figure out how to make the readline() function start reading from line 101 to 201 or end of file if numbre of links < 201.

    maybe there is a countline function somewhere or you can implement your own...sometihng like setting a flag (anchor?) after 101 and 201 etc.

    it could work.

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, I am not good with these files commands but I am still going to post.
    I think astericks that this is quite opposite since I guess that new links are always added at the bottom of the file.

    I would read all the lines into an array and order it backwards and then use for loop to print it out.

    Just in idea though...
    - website

  4. #4
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    end of file...hmmm

    well, you could use
    http://www.php.net/manual/en/functio...t-contents.php

    and then use the explode() function alongwith a delimiter to put your results in an array, get array size and do the same limit thing i posted above except that you'll be going from end_of_array to end_of_array - 100

    it doesnt sound too efficient though.


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
  •