PHP & MySql Blog Comment

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amsterdam
Forum Newbie
Posts: 5
Joined: Sun Mar 16, 2008 8:04 pm

PHP & MySql Blog Comment

Post 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.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: PHP & MySql Blog Comment

Post 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.
User avatar
blue-printf
Forum Newbie
Posts: 12
Joined: Mon Jan 12, 2009 9:27 am

Re: PHP & MySql Blog Comment

Post by blue-printf »

edit: pretty much the same as post above.
amsterdam
Forum Newbie
Posts: 5
Joined: Sun Mar 16, 2008 8:04 pm

Re: PHP & MySql Blog Comment

Post by amsterdam »

Cool. I will give it a try. Thanks
Post Reply