Page 1 of 1

Need help writing information...

Posted: Sat Jun 14, 2003 11:47 am
by Drachlen
Hey guys... I need help again. I have a page which i use to post news, after i submit it goes to a file that writes the information to a document which is included on the main page. The problem is, when i post new news, its added below the older news. Is there any way to tell it to write it at the top instead of the bottom?

This is what i use to write the information:

Code: Select all

<META HTTP-EQUIV="refresh" content="2;URL=Http://morte-satanica.cjb.net">
<?PHP
$name = $_GET['name']; 
$news = $_GET['news'];

$da = date("F j, Y h:i:s A T");

$str = "<br><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 width=590 bgcolor=#404040>
	<TD width=550 align=left bgcolor=#363636><img src=lcor.png><font face=Verdana Color=#7F8F7F><b>Posted by: $name</TD>
	<TD width=550 align=right bgcolor=#363636><font face=Verdana Color=#7F8F7F valign=top><b>$da<img src=rcor.png></TD>
	<TR>
	<TD colspan=2 bgcolor=#404040><font face=Verdana Color=#C9C8C1>&nbsp;&nbsp;&nbsp;&nbsp;$news</TD>
	</table>";

$fp = fopen("./newslog11.html", "a+"); 


fputs($fp, $str); 


fclose($fp);

   echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
	 <TD>The news has been updated. You will be forwarded there now. If your browser doesn't send you, click <a href=http://morte-satanica.cjb.net/>here</a></table>";
?>
-Drachlen

mode

Posted: Sat Jun 14, 2003 5:19 pm
by phpScott
There are several modes that you can use to add info to a file.

You are currently using a+ which will append new lines to the end of the file.

There is also r+ which says :OPEN a file for reading and writinf, Data will be written to the beginning of an existing file.

so your line

Code: Select all

$fp = fopen("./newslog11.html", "a+");
should read

Code: Select all

$fp = fopen("./newslog11.html", "r+");
phpScott

Posted: Sat Jun 14, 2003 5:43 pm
by Drachlen
Thank you... It works but it seems to delete the old entry.. Is the any way i can keep the older stuff?

Posted: Mon Jun 16, 2003 12:13 pm
by Drachlen
Anyone?

Posted: Fri Jun 20, 2003 2:57 pm
by r77
I would also be interested to fiogure this out :)

two files

Posted: Fri Jun 20, 2003 3:19 pm
by phpScott
You could write the existing file to a temp file then write the new stuff into the existing file the write the stuff from the temp file back in.
Might not be effiecient but it would work.

Do you not access to a db to store the stories in because you could then just time stamp the each record and then order them by date/time.

phpScott