<!!-- CONTINUED --!!>
$query = "SELECT * FROM news WHERE id=$id";
$result = mysql_query ($query);
// Since you stated the ID in the function (which we will use as a $_GET later on) then you now have the variable "$id". So you order the news by
that id, so the news you select will be shown, and nothing else.
if (mysql_num_rows ($result) == 0) {
echo "<center><b>Error!</b></center>\n";
echo "<p>No News Exists for the ID specified. Please try again.</p>\n";
return;
// If no id exists in the database, echo an error code...
// But if it did work, make $row an array of the columns, and start the news showing process...
}
$row = mysql_fetch_assoc($result);
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$title = htmlentities ($row['title']);
$news = strip_tags ($row['newstext'], '<a><b><i><u>');
$news = nl2br ($news);
// Same thing as before.....NL2BR and strip the tags so only they show up, and no other funky tags like <table> show up. If you want colors to be added
into your news posts, then add the <font> tag there...
echo "<TR><TD align=\"center\"><b><p>$title</p></b></TD>
</TR>\n";
echo "<tr><td align=\"center\"><p><<<-------------------
------------------------>>></p></td></tr>\
n";
echo "<TR><TD><p>$news</p></TD></TR>\n";
echo "</TABLE>\n";
echo "<BR>\n";
// Now, this next part will intervein with the admin login script. So, you can either study this now, and come back to it, or you can wait til' I explain it
at the admin_login.php page... But I'm not explaining this right now....
//-- ADMIN OPTIONS --\\
echo "<Center>";
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo "";
}else{
echo "<hr color=\"#666666\" width=\"50%\" />";
echo "→ <b><a href=\"/news/index.php?action=editnews129&
id=$id\">Edit News</a></b>
--
<b><a href=\"/news/index.php?action=deletenews12
9&id=$id\" onClick=\"return confirm('Are you sure you really want to start to try to delete this valuable piece of information that can never be retrieved no matter how hard I trys?')\">Delete News</a></b> ←";
echo "<hr color=\"#666666\" width=\"50%\" />";
}
echo "</center>";
//-- END ADMIN OPTIONS --\\
echo '<center><a href="' . $_SERVER[PHP_SELF] . '?action=showcom&id=' . $id . '">Show Comments</a></center>';
// This echos to show the comments, since this is the part that you aren't showing comments...
}
// And this is the function WITH comments...
function displayOneItem_withComments($id) {
global $db;
$query = "SELECT * FROM news WHERE id=$id";
$result = mysql_query ($query);
// blah blah blah...already explained.
if (mysql_num_rows ($result) == 0) {
echo "<center><b>Error!</b></center>\n";
echo "<p>No News Exists for the ID specified. Please try again.</p>\n";
return;
}
$row = mysql_fetch_assoc($result);
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$title = htmlentities ($row['title']);
$news = strip_tags ($row['newstext'], '<a><b><i><u>');
$news = nl2br ($news);
echo "<TR><TD align=\"center\"><b><p>$title</p></b></TD>
</TR>\n";
echo "<tr><td align=\"center\"><p><<<-------------------
------------------------>>></p></td></tr>\
n";
echo "<TR><TD><p>$news</p></TD></TR>\n";
echo "</TABLE>\n";
echo "<BR>\n";
// Again with the admin options...This just makes it so you can see the admin panel even WHEN you are showing comments...der.
//-- ADMIN OPTIONS --\\
echo "<Center>";
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo "";
}else{
echo "<hr color=\"#666666\" width=\"50%\" />";
echo "→ <b><a href=\"/news/index.php?action=editnews129&
id=$id\">Edit News</a></b>
--
<b><a href=\"/news/index.php?action=deletenews12
9&id=$id\" onClick=\"return confirm('Are you sure you really want to start to try to delete this valuable piece of information that can never be retrieved no matter how hard I trys?')\">Delete News</a></b> ←";
echo "<hr color=\"#666666\" width=\"50%\" />";
}
echo "</center>";
//-- END ADMIN OPTIONS --\\
displayComments($id);
}// This says to display the comments function, with the $id that is already specified... so the right new posts' comments come up..
function displayComments($id) {
global $db;
$query = "SELECT * FROM news_comments WHERE news_id=$id";
$result = mysql_query ($query);
echo '<center><a href="' . $_SERVER[PHP_SELF] . '?action=show&id=' . $id . '">Show without Comments</a></center>';
echo "<center><h3>Comments</h3><HR width=\"100%\"></center>\n";
// This shows the link to go back to showing without comments...
while ($row = mysql_fetch_assoc ($result)) {
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$name = htmlentities ($row['name']);
echo "<TR><TD><u>Posted by <b>$name</b></u>";
echo "</TD></TR>\n";
$comment = strip_tags ($row['comment'], '<a><b><i><u>');
$comment = nl2br ($comment);
echo "<TR><TD><p>$comment</p></TD></TR>\n";
echo "<tr><td align=\"left\" valign=\"top\">";
// This just echo's the comments...
//--- ADMIN PANEL --\\
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo "";
}else{
echo "<p>← <a href=\"/news/index.php?action=editcom129&i
d={$row['id']}\">Edit Comment</a> -- <a href=\"/news/index.php?action=deletecom129
&id={$row['id']}\" onClick=\"return confirm('Are you sure you really want to start to try to delete this valuable piece of information that can never be retrieved no matter how hard I trys?')\">Delete Comment</a> →</p>";
}
echo "</tr></td>";
echo "<tr><td><p>==============================
======================</p></td></tr>\n";
echo "</TABLE>\n";
echo "\n";
}// Separater for comments....
<!-- CONTINUED !!-->