PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 13th, 2000, 07:58 AM
pjlewis pjlewis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 22 pjlewis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to pjlewis
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.

Reply With Quote
  #2  
Old July 13th, 2000, 08:24 AM
scollo scollo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 1999
Posts: 114 scollo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 44 sec
Reputation Power: 15
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;

Reply With Quote
  #3  
Old July 13th, 2000, 08:33 AM
pjlewis pjlewis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 22 pjlewis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to pjlewis
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.

Reply With Quote
  #4  
Old July 13th, 2000, 10:02 AM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
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....

Reply With Quote
  #5  
Old July 13th, 2000, 12:07 PM
Chris Pickett Chris Pickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 59 Chris Pickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
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).]

Reply With Quote
  #6  
Old July 13th, 2000, 01:22 PM
polman polman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 45 polman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
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

Reply With Quote
  #7  
Old July 13th, 2000, 02:21 PM
scollo scollo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 1999
Posts: 114 scollo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 44 sec
Reputation Power: 15
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).]

Reply With Quote
  #8  
Old July 13th, 2000, 04:40 PM
pjlewis pjlewis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 22 pjlewis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to pjlewis
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.

Reply With Quote
  #9  
Old July 13th, 2000, 10:45 PM
pjlewis pjlewis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 22 pjlewis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to pjlewis
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.

Reply With Quote
  #10  
Old July 13th, 2000, 11:09 PM
pjlewis pjlewis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 22 pjlewis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to pjlewis
OOOPS!!!! Sorry,
I had my names mixed.
The FILO problem was solved using polman's reply.
Sorry polman.

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > FILO (First In Last Out)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap