Make it read & write to the top..

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
shimmyshine
-


Joined: 01 Jul 2006
Posts: 17

PostPosted: Mon Aug 07, 2006 12:34 am    Post subject: Make it read & write to the top.. Reply with quote

Ok I am making a shoutbox.. works great but for some reason when it writes it.. it writes to the end.. and not to the top.. or I want it to write to the top line.. BUT not delete everything in there.. And I can't figure it out.. "a" writes to the end, a+ writes & reads from the end but doesn't work.. r doesn't work neither does r+.. and I can't figure it out ... Anyone possibly know?

Thanks

ShimmyShine
Back to top View user's profile Send private message
Tim1681
-


Joined: 17 Jan 2005
Posts: 160
Location: Bristol, CT, USA

PostPosted: Mon Aug 07, 2006 5:02 am    Post subject: Reply with quote

I took a quick glimpse at my PHP for retards book and i didn't see anything about setting PHP up to Read & Write to the first line... nor did I see a way possible that you could sort the in-comming lines from first to last other than the way fread spits it out... but I'm sure someone could figure out a way...

But I do know that if you use a database like MySQL you can order the posts on the ShoutBox by their ID, which you can easily code into a program the ShoutBox you are talking about.
_________________
mysql> SELECT * FROM users WHERE clue > 0;
0 rows returned.

Back to top View user's profile Send private message AIM Address
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Mon Aug 07, 2006 9:56 am    Post subject: Reply with quote

To get it to write from the top you need to open the file, save it to a temp variable, get the message to write to the top, add the temp variable after it and then save the lot into a text file.

EG.

Code:
Open File
Save files contents to $temp
Get new message contents $msg
Add $msg and $temp together to make $contents
Write $contents to the file


Just some pseudocode for you to work with.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Mon Aug 07, 2006 3:22 pm    Post subject: Reply with quote

You could use a MySql Database and set each post to have a unique ID (using auto_increment) then the select statment would be somthing like:

Code:
$query = "SELECT * FROM shoutbox ORDER BY `id` DESC";

_________________
My online Portfolio
Back to top View user's profile Send private message Send e-mail MSN Messenger
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Mon Aug 07, 2006 4:33 pm    Post subject: Reply with quote

This should do it.
Quote:

$oldcontent = file_get_contents("file.txt");
$handle = fopen("file.txt", "w");
fwrite($handle, $newcontent."\n".$oldcontent);
fclose($handle);
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group