Forum Moderators: coopster
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
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)
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."
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