How can I add multiple comments to a single post? how can I write code? how can I create a database?

Source: Internet
Author: User
How do I handle multiple comments in one post? how do I write a database? how do I create one post? how do I know more about multiple comments? & nbsp; & lt ;? Php * connect to the database * $ connmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot; 111 & quot;); mysql_select_db (& quot; regis one post multiple comments how to handle code how to write database how to build
I don't understand the details of multiple comments in one post
/* Connect to the database */
$ Conn = mysql_connect ("localhost", "root", "111 ");
Mysql_select_db ("register", $ conn );
Mysql_query ("set names utf8 ");
$ Arr = mysql_query ("select * from luntan where id = $ _ GET [id]", $ conn );
/* Use the while statement to loop through the array returned by the mysql_fetch_array () function */
While ($ result = mysql_fetch_assoc ($ result )){
?>



Author:

Reply Time:



Comment:


Answer

------ Solution --------------------
It seems that your comments and articles are put together!
This is generally not the case.
Create a comment table with the following fields:
Id article id comment content publisher Title contact information, etc.
In this way, when selecting a comment for an article, first obtain the id (id) of the article, and then SELECT * FROM comment table WHERE article id = the obtained Article id.
------ Solution --------------------
There is no relationship between posting and comments. The key is how to determine the comments.
So you need to add a field to save the post id
Id of the post or comment
Pid Post id

In this way, you can use select * from tbl_name where id = $ id or pid = $ id order by pid = 0 to read the post and comment, and put the post in front

If you allow comments (this is the tree)
To avoid recursive queries, you need to add another field
Id of the post or comment
Id of the comment commented on after the id of the pid Post
Mid Post id

Used for reading
Select * from tbl_name where id = $ id or mid = $ id order by mid = 0, pid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.