|
Modified News w/PHP and MySQL problem..
I'm trying to modify the PHP/MySQL News with comments tutorial (http://codewalkers.com/tutorials.php?show=19) The few modifications that I have put in are: 1) I don't use the comments, and 2) I only display the title, poster (added to the database), and date normally, then they click on the linked Title and it (is supposed to) display all the news info.
My problem is that whenever I click on the link for the displaying each individual news item, it does not work (example code: http://www.ehcwfed.com/test/mainsite.php )
php Code:
Original
- php Code |
|
|
|
<?PHP /* user config variables */ $max_items = 8; /* max number of news items to show */ /* make database connection */ function displayNews($all = 0) { /* bring in two variables * $db is our database connection * $max_items is the maximum number * of news items we want to display */ /* query for news items */ if ($all == 0) { /* this query is for up to $max_items */ $query = "SELECT id,poster,title," . "DATE_FORMAT(postdate, '%m-%d-%Y') as date " . "FROM newsdata ORDER BY postdate DESC LIMIT $max_items"; } else { /* this query will get all news */ $query = "SELECT id,poster,title,newstext," . "DATE_FORMAT(postdate, '%m-%d-%Y') as date " . "FROM newsdata ORDER BY postdate DESC"; } /* display news in a simple table */ /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = $row['date']; $poster = $row['poster']; $id = $row['id']; /* display the data */ echo "<TR align="center "><TD id="tabblue "><a href="{$_SERVER['PHP_SELF']}" . "?action=show&id=$id">$title</a> posted by $poster, on $date</TD></tr>n"; } } function displayOneItem($id) { /* query for item */ $query = "SELECT id,poster,title,newstext," . "DATE_FORMAT(postdate, '%m-%d-%Y') as date " . "FROM newsdata " . "WHERE id=$id " . "ORDER BY postdate DESC"; /* if we get no results back, error out */ echo "Invalid news ID number.n"; return; } /* easier to read variables and * striping out tags */ $date = $row['date']; $poster = $row['poster']; /* display the data */ echo "<TR align="center "><TD id="tabblue "><b>$title</b> posted by $poster, on $date</TD></tr>n"; echo "<tr align="center "><TD id="tabblue ">$news</TD></TR>n"; } /* this is where the script decides what do do */ switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; default: displayNews(); } echo "<br><a href="{$_SERVER['PHP_SELF']}" . "?action=all">View all news</a>n"; ?>
|