Jump to content


[PHP]News Systems + Tables


3 replies to this topic

#1 Davidshouse

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 21 March 2006 - 05:02 PM

Well basically, I have a news submission part of my site, The news gets submitted fine, but I'd like the news to be in a table, and then when every bullitin is made, it continues the table. Here is my code:

Quote

<style type="text/css">
<!--
body {
	background-color: #000000;
}
body,td,th {
	color: #FFFFFF;
}
.style1 {
	font-family: "Courier New", Courier, monospace;
	color: #FF0000;
	font-weight: bold;
}
-->

</style>

<h1 align="center"><span class="style1"><U>OMG NEWS BULLETIN </U></span></h1>
<FORM action="/added.php" method="POST">
  <div align="center">
	<table width="743" border="0">
	  <tr>
		<td width="182">Title of News Bulletin: </td>
		<td width="545" colspan="2"><div align="center">
		  <input type="TEXT" name="title">
		</div></td>
	  </tr>
	  <tr>
		<td><br>
		News:</td>
		<td colspan="2"><div align="center">
		  <textarea name="news" cols="50" rows="10"></textarea>
		</div></td>
	  </tr>
	  <tr>
		<td>Posted by: </td>
		<td colspan="2"><div align="center">
		  <input type="text" name="posted" />
		</div></td>
	  </tr>
	  <tr>
		<td><br></td>
		<td><p align="center">&nbsp;
			</p>
		  <p align="center">
			<input type="reset" name="Reset" value="Reset" />
			</p>
		<p align="center">&nbsp;</p></td>
		<td><div align="center">
		  <input type="SUBMIT" name="submit" value="Submit" />
		</div>
			  </td>
	  </tr>
	</table>
  </div>
  <p align="center">
	<label></label>
	<br>
  </p>
</FORM>

Quote

<?php
$da = getdate();
$date= Date('d/m/y');
$news = ("

  <tr>
	<td><b><div align=\"center\">$date</div></b></td>
	<td><p>$news</p>
	<p align=\"right\"><b>$posted</b></p>
	</td>
  </tr>
</font>");

$file = fopen("news.php", "r");
$read = fread($file, filesize("news.php"));
fclose($file);
$blah = fopen("news.php", "w"); //Leave alone look and learn, only edit if you know php
$news=stripslashes($news);
fwrite($blah, "$news $read");
fclose ($blah);
print "<meta http-equiv=\"refresh\" content=\"1;http://davidshouse.awardspace.com/news.php/\">"; //edit path to where the news.php file falls
?>

Quote

  <tr>
	<td><b><div align="center">21/03/06</div></b></td>
	<td><p>This is a test bulletin</p>
	<p align="right"><b>David</b></p>
	</td>
  </tr>
</font> <table border="3">


<style type="text/css">
<!--
body {
	background-color: #000000;
}
body,td,th {
	color: #FFFFFF;
}
.style1 {
	font-family: "Courier New", Courier, monospace;
	color: #FF0000;
	font-weight: bold;
}
-->

</style>
</table>

Basically, it all goes "Wrong" in news.php.

When the form submits, the data it's submitting is going ABOVE the <table> tag insted of Below it. If it went below it, it would show in a table.

So I guess what i am asking is how can I make the code it submits go underneath a certain tag in my source.

I don't want the form to submit another table every time, as you can see; I'd like it to continue the already there table.

Thanks for whatever help you give me.

David.

#2 Hit3k

    Young Padawan

  • Members
  • Pip
  • 120 posts
  • Gender:Male
  • Location:Australia

Posted 21 March 2006 - 07:02 PM

Do it like
<?php
echo '<table border="0" cellspacing="0" cellpadding="0">;
News Code
echo '</table>';
?>
I dunno if that helps much but its worth a try :D

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 March 2006 - 10:17 PM

Change
$file = fopen("news.php", "r");
$read = fread($file, filesize("news.php"));
fclose($file);
$blah = fopen("news.php", "w"); //Leave alone look and learn, only edit if you know php
$news=stripslashes($news);
fwrite($blah, "$news $read");
fclose ($blah);
To
$read = implode('', file('news.php'));
$news = str_replace('<table border="3">', "<table border=\"3\">\n".$news."\n", $read);
$fp = fopen('news.php', 'w');
fwrite($fp, $news);
fclose($fp);
Keep in mind it looks like you're also using improper HTML, you should have the <style> tag in the <head> section, and the </font> tag doesn't look like it's ever opened, but at the rate it's going, it will be closed after every post.
But since we're here to discuss php, not html, let me know how this works out for you.

#4 Davidshouse

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 22 March 2006 - 11:25 AM

Okay, Well, I'm pretty sure the HTML works, but I'll try the PHP, and tell you how I get on.

Thanks so much

EDIT: It works, thank-you very much guys.

Edited by Davidshouse, 22 March 2006 - 11:52 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users