danmc Posted March 27, 2008 Share Posted March 27, 2008 Sorry If this is abit vague but i'm in my first year at uni & a complete beginner to php etc. I have made a basic blog using dreamweaver, split it into topics and the topics articles. I have used dynamic tables to display the articles from a mysql database. Now here's where I have come unstuck I can not get the comments to display only on the article being commented on?. They either display on all articles or just one post with matching id's when I try and use a filter?. I have been using another dynamic table for the comments with a record insertion form on the same page as the article. Any help would be Greatly appreciated Thanks. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/ Share on other sites More sharing options...
cunoodle2 Posted March 27, 2008 Share Posted March 27, 2008 post some code to give us something to look at. Be sure to block out all usernames and passwords prior to posting code. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502356 Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 My suggestion is to drop dreamweaver. There's not substitute for understanding a language as complex as PHP thoroughly. If you keep using dreamweaver to code you're going to consistently run into issues you won't be able to solve on your own. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502360 Share on other sites More sharing options...
soycharliente Posted March 27, 2008 Share Posted March 27, 2008 Why is using Dreamweaver bad? I disagree personally. It's the same as using some other text editor to program in. It doesn't matter what you using to write your code. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502365 Share on other sites More sharing options...
danmc Posted March 27, 2008 Author Share Posted March 27, 2008 Heres the page this is my first assignment and I'm a complete beginner thats why i'm using dreamweaver at the minute. <?php require_once('Connections/cet_mysql_01.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO Comments (ComEmail, ComName, ComText, ComDate) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['ComEmail'], "text"), GetSQLValueString($_POST['ComName'], "text"), GetSQLValueString($_POST['ComText'], "text"), GetSQLValueString($_POST['ComDate'], "date")); mysql_select_db($database_cet_mysql_01, $cet_mysql_01); $Result1 = mysql_query($insertSQL, $cet_mysql_01) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <?php require_once('Connections/cet_mysql_01.php'); ?> <?php mysql_select_db($database_cet_mysql_01, $cet_mysql_01); $query_rsTopics = "SELECT * FROM Topics ORDER BY TopicTitle ASC"; $rsTopics = mysql_query($query_rsTopics, $cet_mysql_01) or die(mysql_error()); $row_rsTopics = mysql_fetch_assoc($rsTopics); $totalRows_rsTopics = mysql_num_rows($rsTopics); $colname_rsArticle = "-1"; if (isset($_GET['ArticleId'])) { $colname_rsArticle = (get_magic_quotes_gpc()) ? $_GET['ArticleId'] : addslashes($_GET['ArticleId']); } mysql_select_db($database_cet_mysql_01, $cet_mysql_01); $query_rsArticle = sprintf("SELECT * FROM Articles INNER JOIN Topics ON ArticleTopicId=TopicId WHERE ArticleId = %s", $colname_rsArticle); $rsArticle = mysql_query($query_rsArticle, $cet_mysql_01) or die(mysql_error()); $row_rsArticle = mysql_fetch_assoc($rsArticle); $totalRows_rsArticle = mysql_num_rows($rsArticle); $maxRows_Comments = 10; $pageNum_Comments = 0; if (isset($_GET['pageNum_Comments'])) { $pageNum_Comments = $_GET['pageNum_Comments']; } $startRow_Comments = $pageNum_Comments * $maxRows_Comments; mysql_select_db($database_cet_mysql_01, $cet_mysql_01); $query_Comments = "SELECT * FROM Comments ORDER BY ComDate DESC"; $query_limit_Comments = sprintf("%s LIMIT %d, %d", $query_Comments, $startRow_Comments, $maxRows_Comments); $Comments = mysql_query($query_limit_Comments, $cet_mysql_01) or die(mysql_error()); $row_Comments = mysql_fetch_assoc($Comments); if (isset($_GET['totalRows_Comments'])) { $totalRows_Comments = $_GET['totalRows_Comments']; } else { $all_Comments = mysql_query($query_Comments); $totalRows_Comments = mysql_num_rows($all_Comments); } $totalPages_Comments = ceil($totalRows_Comments/$maxRows_Comments)-1; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><!-- InstanceBegin template="/Templates/DanBlog.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- InstanceBeginEditable name="doctitle" --> <title>Blog: Article</title> <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --> <link href="Templates/danblog.css" rel="stylesheet" type="text/css"> <!-- InstanceEndEditable --> <link href="/Templates/danblog.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" cellspacing="7" cellpadding="0"> <tr valign="top"> <td colspan="2"><img src="images/logo.jpg" width="258" height="179"></td> </tr> <tr valign="top"> <td width="15%"> <table border="0" cellpadding="0" cellspacing="0" class="TopBox"> <tr> <td valign="top" class="TopBoxHead">Topics</td> </tr> <?php do { ?> <tr> <td class="TopBody"><a href="topic.php?TopicId=<?php echo $row_rsTopics['TopicId']; ?>"><?php echo $row_rsTopics['TopicTitle']; ?></a></td> </tr> <?php } while ($row_rsTopics = mysql_fetch_assoc($rsTopics)); ?> </table></td> <td><!-- InstanceBeginEditable name="main" --> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="TopicText"> <tr class="TopBoxHead"> <td><?php echo $row_rsArticle['TopicTitle']; ?> > <?php echo $row_rsArticle['ArticleTitle']; ?></td> <td><div align="right">Published: <?php echo $row_rsArticle['ArticleDate']; ?></div></td> </tr> <tr> <td colspan="2" class="HeaderBody"><?php echo $row_rsArticle['ArticleDescription']; ?></td> </tr> <tr> <td colspan="2"><?php echo $row_rsArticle['ArticleText']; ?></td> </tr> </table> <p> </p> <table width="100%" border="1"> <?php do { ?> <tr> <td width="3%"> </td> <td width="49%"><?php echo $row_Comments['ComName']; ?></td> <td width="48%"><?php echo $row_Comments['ComDate']; ?></td> </tr> <tr> <td> </td> <td colspan="2"><?php echo $row_Comments['ComEmail']; ?></td> </tr> <tr> <td> </td> <td colspan="2"><?php echo $row_Comments['ComText']; ?></td> </tr> <?php } while ($row_Comments = mysql_fetch_assoc($Comments)); ?> </table> <p> </p> <form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">Email:</td> <td><input type="text" name="ComEmail" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Name:</td> <td><input type="text" name="ComName" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Comment:</td> <td><input type="text" name="ComText" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Insert record"></td> </tr> </table> <input type="hidden" name="ComDate" value="<?php echo date('Y-m-d H:i:s'); ?>"> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> <!-- InstanceEndEditable --></td> </tr> <tr valign="top"> <td colspan="2"><div align="center">Spare tester link <br> <a href="http://www.danmc.info" target="_blank"> Danmc.info</a></div></td> </tr> </table> </body> <!-- InstanceEnd --></html> <?php mysql_free_result($rsTopics); mysql_free_result($rsArticle); mysql_free_result($Comments); ?> Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502375 Share on other sites More sharing options...
danmc Posted March 27, 2008 Author Share Posted March 27, 2008 To be honest I haven't looked at the code itself because I'm a bit of a php noob. I know I need a a way to associate each set of comments to each article but just cant figure out how?. Do I expand the Article table to include room for comments? Any help would be great thanks. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502431 Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 Why is using Dreamweaver bad? I disagree personally. It's the same as using some other text editor to program in. It doesn't matter what you using to write your code. Dreamweaver is not so much of an environment as it is a 'make-the-code-for-you' application. The problem is that most who uses it for php doesn't use it to write code. As a coding environment, it's extremely bloated... mostly because it's not supposed to be used as just a plain-text editor. Hence why most people who code do not use dreamweaver. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502433 Share on other sites More sharing options...
soycharliente Posted March 27, 2008 Share Posted March 27, 2008 To me, the best way to layout some kind of blog as far as your SQL tables go is something like this ... users -------- id username password email firstname lastname etc. posts ------- id author_id <- an id from the users table, who made the post post_date <- datetime type for returning in order title body etc. comments ------------ id author_id <- an id from the users table, who made the comment post_id <- an id from the post table, ie which post they commented on comment_date <- datetime type for returning in order title body etc. You can associate each table to the other tables with the overlapping information. SELECT * FROM posts p JOIN users u ON p.author_id=u.id With that you can have access to the username, firstname, lastname, email, etc. of the person and have access to all the information about their post like the title, body, and post_date SELECT * FROM comments c JOIN users u ON c.author_id=u.id WHERE post_id='$id' With that, you get back all the comments for a defined post and you have access to each comment author's information in the same way as the posts. Does any of the make sense? This is a very basic explanation. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502442 Share on other sites More sharing options...
danmc Posted March 27, 2008 Author Share Posted March 27, 2008 Certainly does cheers I'll try it after I get back from the gym Thanks. Link to comment https://forums.phpfreaks.com/topic/98186-a-comment-box-that-associates-with-its-own-article-in-my-diy-blog/#findComment-502454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.