Jump to content

News Script


Drezard

Recommended Posts

Hello, Im trying to make a news script, except im currently stuck. I need someone to finish this off for me (or atleast guide me)

 

Now, I connect to the MySQL Database on another script that uses this class, so dont worry about that.

 

Okay heres the script:

 

<?php

class news_report {

function news_new() {

	echo "<form action='' method='post'>
    	Subject: <input type='text' size='200' name='subject'><br>
    	News: <input type='text'size='10000' name='news'><br>
    	<input type='submit' name='submit'>
    	</form>";

	if (isset($_POST['news'])) {

		$subject = $_POST['subject']; 
		$news = $_POST['news'];
		$date = date("Ymdgi");
		$time = date("g:i A D d F");

		$query ="INSERT INTO news_all (date, subject, news, time) VALUES ('$date', '$subject', '$news', '$time')";

		$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

		echo "News Added";

	}

}

function news_all() {

	$query = "SELECT date, subject, news, time FROM news_all ORDER BY date";

	$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

	if (mysql_num_rows($result) > 0) {

    		while($row = mysql_fetch_row($result)) {

    		}

	} 

}

}

?>

 

Now, I want it too output the first 5 bits of news. In order of the date. So the most recent ones first. I also want it to display the subject at the top, then the time, then the news so....

 

Subject

Time

News

 

Subject

Time

News

 

Like that. Now, how would i do that?

 

Link to comment
https://forums.phpfreaks.com/topic/38438-news-script/
Share on other sites

something like this then:

 

$query = "SELECT date, subject, news, time FROM news_all ORDER BY date LIMIT 5";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

if (mysql_num_rows($result) > 0) {
echo <<<html
<table border="0" width="100%" cellpadding="0" cellspacing="0">
html;

while($row = mysql_fetch_row($result)) {

$row['date'] = date("jS F, Y \a\\t h:ia", strtotime($row['date'])); //change the date to a better format.
echo <<<html
<tr>
<td>{$row['subject']}</td>
</tr>
<tr>
<td>Posted on {$row['date']}</td>
</tr>
<tr>
<td>{$news}</td>
</tr>
<tr><td height="5"></td>
</tr>
html;

}

echo <<<html
</table>
html;
} 

 

hope thats sort of what your looking for.

Link to comment
https://forums.phpfreaks.com/topic/38438-news-script/#findComment-184448
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.