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

    Join Date
    Jun 2000
    Posts
    22
    Rep Power
    0
    Hello,
    I have just written a small guestbook which is working well, however the first guests' comments
    are always the 1st (top).
    My prefered option is to always have the latest comments on top.
    Is there an (easy!!!) way of doing this, like (hopefully) 1 built-in funtion.?
    Thanking you in advance,

    ------------------
    With my kind regards,
    Peter.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    Well, you didn't provide much info about how it works, but if you're using SQL to store the entries, just try:

    select comments from guest order by entrydate desc;
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    22
    Rep Power
    0
    Sorry, it is just a plain old text file!
    Name: Email: & Comments:
    These are saved to a text file with the html <br> and other formatting added.
    As I mentioned it works fine but the FILO is a refinement.
    I do not have any SQL on board nor experience!

    ------------------
    With my kind regards,
    Peter.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    16
    Peter,

    This is not the most elegant way to do it (in the absence of push and pop functions) but it may get you started.

    <?

    if(!($myfile=fopen("guestbook.txt", "r")))
    {
    print"Could not open file";
    exit;
    }

    while($myline=fgets($myfile, 255))
    {
    $bytes[]=ftell($myfile); // get the file pointer vals
    }

    for($i=0; $i<count($bytes)-1; $i++)
    {
    // copy to separate array minus the
    // last value which is EOF
    $bytelist[]=$bytes[$i];
    }

    rsort($bytelist); // reverse it
    $bytelist[]=0; // pad the end with 0, the beginning of the file

    for($i=0; $i<count($bytelist); $i++)
    {
    fseek($myfile, $bytelist[$i]);
    $myline=fgets($myfile, 255);
    print"$myline<BR>";
    }

    fclose($myfile);

    ?>

    If your file has more than 255 per line, adjust accordingly....
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    59
    Rep Power
    15
    hmm, or you could use file()

    // Put Guest Book into an Array
    $myarray = file("myguests.txt");
    // Reverse Array
    $myarray = array_reverse($myarray);

    For this to work you must have PHP4 and each entry for the guest book on it's own serperate line.

    Chris

    [This message has been edited by Chris Pickett (edited July 13, 2000).]
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    15
    You could (something like the above comment)

    $file = file("text.txt");
    $size = sizeof($file) - 1;
    for($i=$size;$i>=0;$i--)
    echo $file[$i];

    whatever floats your boat
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    I agree that the file() function (with one of the two solutions above) is the best bet; but just for the record, PHP4 does have array_push() and array_pop():

    http://www.php.net/manual/ref.array.php

    [This message has been edited by scollo (edited July 13, 2000).]
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    22
    Rep Power
    0
    Thanks peoples,
    I will play around with the provided options and see what happens.
    Am unable to compile PHP4 so using PHP 3.0.12.

    Again thanks,

    ------------------
    With my kind regards,
    Peter.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    22
    Rep Power
    0
    FILO fixed.
    I ended up using a slight variation of scollo's reply.
    <?
    $myarray=file("GBFile.txt");
    for($1=count($myarray)-1;$i>=0;$i--) {
    echo $myarray[$i];
    }
    and it appears to work.
    Thanks again.

    ------------------
    With my kind regards,
    Peter.
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    22
    Rep Power
    0
    OOOPS!!!! Sorry,
    I had my names mixed.
    The FILO problem was solved using polman's reply.
    Sorry polman.

    ------------------
    With my kind regards,
    Peter.

IMN logo majestic logo threadwatch logo seochat tools logo