简体   繁体   中英

MySQL Table for comments

I made a link to a page in a document named "find.php" and made $id equal to the id of an article. When you click on it, the url looks like find.php?id=w/e . I want to be able to post comments on the page. For instance if I wanted to post a comment on find.php?id=40 , how would I display the comments? By the way, there's a table for the articles and a table for the comments.

For reference, I set up my comments table as

com_id int (11)
title text
user varchar (255)
msg text

Would I need a foreign key also?

tableArticle:

id (int) PK
...
...

tableComment:

com_id (int) PK
article_id (int) FK to tableArticle on id
comment (varchar(255))

To display comments:

Your SQL query:

SELECT * FROM tableComment WHERE article_id = w\e id

Your code (note that I can't test the syntax now):

while($row=mysql_fetch_array($result)) 
{
     echo $row[1];
}

Yes, you will need a foreign key from the comments table to the articles table, so you can reference which article each comment is for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM