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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.