Forum Moderators: coopster

Message Too Old, No Replies

Main content with comments

a page where people can comment about a subject you posted

         

togethercomms

2:21 am on Jul 1, 2009 (gmt 0)

10+ Year Member



I am working on a website where my client wants to upload a subject and let people comment on them how they want.

Now i have created the table where it holds the subject which is working

now i need to find a way of having comments underneath that subject which are linked to that.

If you could help me that would be great

Many Thanks

chief stains

9:55 am on Jul 1, 2009 (gmt 0)

10+ Year Member



You may be better off going with something like Wordpress or Drupal if you're looking for this functionality.

Otherwise, the way do it is offer a form to the user at the bottom of the page where the subject is displayed with fields for e.g. name, email and comment. When the form is sent it stores them in a new table called 'Comments' where there are at least five fields, id (of the comment, auto increment), subject_id (id of the subject that the comment is associated with), user name, email and comment.

Then when you are printing out the subject, again at the bottom of the page, have a select statement that says SELECT user_name, email, comment FROM comments WHERE subject_id = the subject that is being displayed (I presusme this will be a GET variable in the form of *.php?sid=4)

rocknbil

4:19 pm on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure that's something like

SELECT user_name, email, comment FROM comments WHERE subject_id =1234 and approved=1

where "approved" defaults to zero and is only set by some "admin" function you create. Page comments/blogs are the new "guest book" in that automated submissions from spammers will bury you if they find out the content becomes immediately available on submit. They may still hit you up but won't waste their time if all comments need to be "approved."

NeilsPHP

6:03 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



another way is to create a new table each time the subject is offered for comments.that table may be like this:

CREATE TABLE IF NOT EXISTS `subject_comment_table` (
`id` int(11) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
`user_name` text NOT NULL,
`comments` text NOT NULL,
`approval` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


(make sure assign id as auto-increment)

Now each time somebody makes a comment,you can use-

insert into subject_comment_table (column names) values (column_values) ;

(you can set approval='0' which can be set to'1' after approval by admin)

you can use mysql_table data retrieval methods to show the subject and comments as you prefer