...

View Full Version : News Script



pogester
06-09-2007, 12:04 AM
Hi there, I am fairly new to PHP and am looking for some help.

I have written a basic news script so that myself and others can add news to the site throught the browser, however at the moment the full news for each article is displayed on the home page, I am looking to make it so that the headline only is displayed and then visitors click on that to read the full article.

I have a news.php file which displays the headlines, when you click on the name of the news article it loads viewArticle.php for that news item, however when it loads this all I see is the line Posted by:

I have attached the code for both pages, I am lost as to where I am going wrong and any help would be much appreciated.

news.php


<?php
include ('mysql_connect.php');
$query = "SELECT id,title,author,post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_data";
$result = @mysql_query($query);

if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$url = 'comments.php?id='.$row['id'];
echo '<p> <a href="viewArticle.php?id='.$row['id'].'">';
echo $row['title'];
echo '</a></p>';
}
} else {
echo 'There are no news posts to display';
}
?>

viewArticle.php


<?php
include ('mysql_connect.php');

if(is_numeric($_GET["id"])) {
$id = $_GET["id"];
}

if(isset($id)) {
$query = mysql_query("SELECT * FROM news_data WHERE id = '{id}'")or die(mysql_error());
$row = mysql_fetch_assoc($query);

echo '<h1>'.$row['title'].'</h1>

'.$row['sd'].'

Posted by : '.$row['author'].'

'.$row['post'].'

</p>';
}


?>

I look forward to reading your advice

Thanks

Dazz

Fou-Lu
06-09-2007, 12:25 AM
WHERE id = '{id}'
id is not being parsed, just change it to WHERE id = $id and it will work.

pogester
06-09-2007, 12:55 AM
Works fine now, thanks a lot for your help, knew it would be something obvious.

Cheers again :thumbsup:

Now I can move on to my next task categories :D

Fou-Lu
06-09-2007, 12:58 AM
Good to hear it worked out :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum