I am along the way of coding my initial blog. With the aid of various lessons, along with other forums I've handled to collect a semi-working code.

At this time I've got a code that can take and shows the comment, the main problem is matching which comments continue which publish. My current system is my publish are HTML files, and also the surveys are saved inside a database. I in addition have a form that produces a brand new row having a unique publish ID and title for every publish.

My fundamental DB setup at this time is the following: 1 database, 2 tables. A publish table along with a comments table. Within the comments table I've the overall title, website, comment, etc. i possess a unique ID that auto-batches for every comment. Then I've got a publish_id that ought to complement with the designated publish.

Around the publish table, I've just two fields: entry_id and title. The title is by hand set by me and also the entry_id is auto-incremented. NOTE: The entry is NOT saved within the database.

So my current problem is how you can set the publish_id for every page of comments and just how to connect the entry_id using the actual publish. I really hope that isn't too confusing. Thanks a lot for just about any help!

-iMaster

I believe that you ought to consider refactoring your code to keep the publish inside your database.

After that, you'd possess a page (http://mysite/showpost.php?post_id=5) that shows your publish (psuedo-code'ish):

<?php

// establish database connection here

// Simple SQL injection prevention:
foreach ($_REQUEST as $key => $value)
{
  $_REQUEST[$key] = mysql_real_escape_string($value);
}

// Get the appropriate post from the posts table.
$query = "SELECT post FROM posts WHERE post_id={$_REQUEST['post_id']}";
$result = mysql_query($query);
$row = mysql_fetch_assoc($query);

echo $row['posts'];

// Get the appropriate comments from the comments table.
$query = "SELECT comment FROM comments WHERE post_id={$_REQUEST['post_id']}";
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result))
{
  echo "Comment: {$row['comment']}";
}

// close connections, etc.    

?>

My PHP is extremely rusty, but this will provide you with a wise decision from the data structure and code required to accomplish what you would like.

Healthy for you for understanding how to "roll your personalInch and obtain exactly what you would like and learn something on the way.

You need to produce a table for comments having a foreign key that suits the content ID.

When exhibiting your comments, perform a query to fetch all comments connected with this article ID.

You need to follow Ian's advise and refactor your code to utilize a table. Otherwise you will have to hard code some PHP whenever you produce the publish html.

like

$actualPostId = 1234; // you get this from the database
file_put_contents ($filename, "<?php \$postID= $actualPostId;?> $rest_of_html");

should i be reading through the issue right, i believe you need to simply add the entry_id towards the comment form like a hidden area so when someone posts a comment, include it as being post_id whenever you place in to the comment table. i believe then you've the missing outcomes of tables.