Page 1 of 1

PHP & MySql Blog Comment

Posted: Fri Jan 16, 2009 3:07 pm
by amsterdam
Hello Helpful Developers,

I' am trying to make a blog and so far so good. The only issue I am having has to do with the comments. I do not know how to combine the comments table to the blog table. So I want specific comments to show up on specific blog posts. Here is my query to select the blog info.

Code: Select all

 
<?
                $id=$_GET['id'];
                $info=mysql_query("select title,author,entry,date_format(date , '%M %e, %Y') date from blog where id='$id' limit 1");
                    $inforow=mysql_fetch_array($info);
                    $title = $inforow[0];
                    $author = $inforow[1];
                    $entry = $inforow[2];
                    $date = $inforow[3];
?>
 
So if i have a form on the same page that is for comments and I insert them into the database how do I add them to the corresponding blog id. Here is my comments table.

table:
comments

fields:
id, int(5), auto increment
name, varchar (255)
comment, text
date, datetime

Any help is much appreciated.

Re: PHP & MySql Blog Comment

Posted: Fri Jan 16, 2009 3:31 pm
by watson516
Add a post_id to the comments table. This value will be the id of the post. When you want the comments of a specific post, query only the comments with the post_id of whatever post.

Re: PHP & MySql Blog Comment

Posted: Fri Jan 16, 2009 3:32 pm
by blue-printf
edit: pretty much the same as post above.

Re: PHP & MySql Blog Comment

Posted: Fri Jan 16, 2009 3:51 pm
by amsterdam
Cool. I will give it a try. Thanks