Jump to content

Add Comment on Post?


nielcleo
 Share

Recommended Posts

Have a table of comments where one of the fields (foreign key) points to your posts table using the ID of the post it's linked to.
having a table in database name comments how it will display the comment if more than two? i cant figure out how it will be linked/or display. i try to post comment in my first post and i commented also at the 2nd post but the comment goes to the comment 1. :)
Link to comment
Share on other sites

Each post needs to be linked to either another post if it's a reply, or a thread if it's the first post. All posts should probably be linked to a thread, but if a post is a reply to another post then you should also be storing the ID of the post that it is in reply to.

Link to comment
Share on other sites

Each post needs to be linked to either another post if it's a reply, or a thread if it's the first post. All posts should probably be linked to a thread, but if a post is a reply to another post then you should also be storing the ID of the post that it is in reply to.
so it will happen like this?correct me if im wrong..example.Post #1 have an id = to 1Post #2 have an id = to 2so if im gonna do the reply on Post #1 should i set the ID of the reply also be = to 1and if im gonna reply on Post #2 then the reply ID also be = to 2.how about if i will do another reply on Post #1? should the reply ID is = to 1 also?
Link to comment
Share on other sites

No, you have another field called "reply_to" or something. If post 2 is a reply to post 1, then you put a 1 in the reply_to field for post 2. All posts have unique IDs. Post 1 would have a 0 in the reply_to field, because it's not a reply to anything.

Link to comment
Share on other sites

No, you have another field called "reply_to" or something. If post 2 is a reply to post 1, then you put a 1 in the reply_to field for post 2. All posts have unique IDs. Post 1 would have a 0 in the reply_to field, because it's not a reply to anything.
waa... i cant imagine the flow..do you mean sir in this they have a same table?im thinking about separate table Post and Comment table..and im got confused on the part when the POST have 2 comment how it will be display?im reading lots of code but they share a simple comment box the problem is you can only reply on the post where you put the comment box..please help.. more appreciated if some give source code.. i cant figure out how it works and how can i do that?.. Edited by nielcleo
Link to comment
Share on other sites

You haven't really described the difference between a post and comment, so I'm not sure if they go in the same table or not. They could go in the same table though. The table would have fields like ID, date, subject, text, author, etc, plus a reply_to field that holds the ID of another post if it was in reply to something. The difference between a post and a comment would be that a post is not a reply to anything, so it would have a 0 in the reply_to field. If there are 3 comments that are all in reply to the same thing, then they have the same ID in their reply_to fields.

Link to comment
Share on other sites

You haven't really described the difference between a post and comment, so I'm not sure if they go in the same table or not. They could go in the same table though. The table would have fields like ID, date, subject, text, author, etc, plus a reply_to field that holds the ID of another post if it was in reply to something. The difference between a post and a comment would be that a post is not a reply to anything, so it would have a 0 in the reply_to field. If there are 3 comments that are all in reply to the same thing, then they have the same ID in their reply_to fields.
ohh sorry for that sir im thinking that 3 or more comment is not possible in one table.. maybe ill try that one. how can i store 3 inputs in reply_to field?about the POST and COMMENT can i rename it to see the difference.let say POST TABLE is QUESTIONS and the COMMENT TABLE is ANSWERS. i separate the table like the table in WORDPRESS BLOG.so what will be the flow for that?if i posted a 2 QUESTIONQUESTION 1QUESTION 2and someone posted an ANSWER in my QUESTION 1 and another person posted ANSWER in QUESTION 1how can i display if Someone posted and ANSWER in QUESTION 2.. this is the part i cant figure out.. Edited by nielcleo
Link to comment
Share on other sites

Here is a default table structure that you can use.

table.BlogPostID TITLE   BODY-- ------- ------------1  Title 1 body text...2  Title 2 body text...table.BlogCommentID PARENT COMMENT-- ------ ---------1  1	  Comment 12  1	  Comment 23  1	  Comment 34  1	  Comment 45  2	  Comment 16  2	  Comment 2table.CommentReplyID PARENT COMMENT-- ------ -------1  1	  Reply 12  2	  Reply 13  3	  Reply 14  3	  Reply 25  4	  Reply 16  5	  Reply 1

Some SQL Queries

SELECT * FROM table.BlogPostSELECT * FROM table.BlogComment WHERE 'PARENT' = 'x'SELECT * FROM table.CommentReply WHERE 'PARENT' = 'y'

The Loop

while($row = mysql_fetch_array($result))  {	$i+=1;	echo $row['body'] . '<br/><br/>';	/* Do the same as above to loop through looking for comments */	while(...)	  {		$ii+=1;		echo $row2['comment'] . '<br/><br/>';		/* Do the same as above to loop thorugh looking for replies */		while(...)		  {			$iii+=1;			echo $row3['reply'] . '<br/><br/>';		  }	  }  }

Edited by dzhax
Link to comment
Share on other sites

Here is a default table structure that you can use.
table.BlogPostID TITLE   BODY-- ------- ------------1  Title 1 body text...2  Title 2 body text...table.BlogCommentID PARENT COMMENT-- ------ ---------1  1	  Comment 12  1	  Comment 23  1	  Comment 34  1	  Comment 45  2	  Comment 16  2	  Comment 2table.CommentReplyID PARENT COMMENT-- ------ -------1  1	  Reply 12  2	  Reply 13  3	  Reply 14  3	  Reply 25  4	  Reply 16  5	  Reply 1

Some SQL Queries

SELECT * FROM table.BlogPostSELECT * FROM table.BlogComment WHERE 'PARENT' = 'x'SELECT * FROM table.CommentReply WHERE 'PARENT' = 'y'

The Loop

while($row = mysql_fetch_array($result))  {	$i+=1;	echo $row['body'] . '<br/><br/>';	/* Do the same as above to loop through looking for comments */	while(...)	  {		$ii+=1;		echo $row2['comment'] . '<br/><br/>';		/* Do the same as above to loop thorugh looking for replies */		while(...)		  {			$iii+=1;			echo $row3['reply'] . '<br/><br/>';		  }	  }  }

thanks for the code sir. i finished the comment but got trouble on some part navigating the page..i want to happen like this in the demo blog.. demo blogi posted one of my code in the thread here. and someone suggested not to use..http://w3schools.invisionzone.com/index.php?showtopic=39134
Link to comment
Share on other sites

for what you are using that would be an easy way to do it but I agree it is not secure. anyone that would wish to hurt your site can easily manipulate the output. you can encrypt the $_GET data with base64 or something else and then decrypt it upon loading or you can use JavaScript to send the page data as $_POST data.EDIT: there are many different ways to do this above is just some easy suggestions. I have heard of something called pagination that might work for you as well. I have not read up on it though.

Edited by dzhax
Link to comment
Share on other sites

for what you are using that would be an easy way to do it but I agree it is not secure. anyone that would wish to hurt your site can easily manipulate the output. you can encrypt the $_GET data with base64 or something else and then decrypt it upon loading or you can use JavaScript to send the page data as $_POST data.EDIT: there are many different ways to do this above is just some easy suggestions. I have heard of something called pagination that might work for you as well. I have not read up on it though.
pagination is used when you want to restrict the output of results to display but still let the user know there are more results or whatnot that are viewable. So if you had 50 results, and you only wanted to display 10 at a time, you would have 5 'pages'. You would start off on page 1 (items 1-10), and have links to the all 'pages'. When you go to page 2, page 2 is highlighted, and it will display results 11-20, etc.Basically you only have one page, like display_results.php, but you set some variables to define the viewport, and then use session or query string values to track the user's offset within the given result set. It also means you would rerun the query each time this one page is loaded.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...