View previous topic :: View next topic |
Author |
Message |
shimmyshine -
Joined: 01 Jul 2006 Posts: 17
|
Posted: Mon Aug 07, 2006 12:34 am Post subject: Make it read & write to the top.. |
|
|
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 |
|
|
Tim1681 -
Joined: 17 Jan 2005 Posts: 160 Location: Bristol, CT, USA
|
Posted: Mon Aug 07, 2006 5:02 am Post subject: |
|
|
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 |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Mon Aug 07, 2006 9:56 am Post subject: |
|
|
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 |
|
|
abyssisthebest -
Joined: 30 Jun 2005 Posts: 319 Location: Boston, UK
|
Posted: Mon Aug 07, 2006 3:22 pm Post subject: |
|
|
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 |
|
|
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Mon Aug 07, 2006 4:33 pm Post subject: |
|
|
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 |
|
|
|