Determining which comment belongs to each article?
Moderator: General Moderators
Determining which comment belongs to each article?
Can someone please tell me how I can determine which comment belongs to each article and which comment belongs to each username? Showing some code would be appreciated. Thanks in advance.
The comments, usernames and articles are in a database but the comments and usernames are in one table and the articles are in another. I am wanting the users to add comments to the articles and to display the comments that belong to that article. When a user clicks on a link it should go to another page where the comments will be displayed. The articles will be added via an admin centre.
It' very easy it' s about database design put a column (foreign key) in the comments table which referes to the article number (which will be the primary key of the articles table). After that you make a simple SQL statment in which you select the comments from joining of the article and comments table on egality of the two columns that I sugested earlier and displaying them on the page you want.
Read more about designing a database and don' t get scared about the many principles and rules it' s hard at the begining but it will be easy once you get the hang of it.
Read more about designing a database and don' t get scared about the many principles and rules it' s hard at the begining but it will be easy once you get the hang of it.
Two tables.
Articles(id, title, summary, content, published, expires, type)
Article_comments(id, articleID, name, comment).
Add a comment
Grab article and comments
Ibbo
Articles(id, title, summary, content, published, expires, type)
Article_comments(id, articleID, name, comment).
Add a comment
Code: Select all
insert into Article_comments (articleID, name, comment) (332, "ibbo", "my comment");Code: Select all
select * from Articles a left join Article_comments c on c.articleID=a.id where a.id = 332;