Database Structure: {code...} after the comments in the relevant article are read, I use recursion to display the comments. But now there is a problem. For example, if I display 10 Comments on one page and want to display the first page, I have read the top-level comments now. But how can I find the best response under these comments? (Because... the database structure:
Create table if not exists 'blog '. 'comments' ('id' bigint unsigned not null AUTO_INCREMENT COMMENT 'comment id', 'content' text not null comment' COMMENT content ', 'create _ time' int unsigned not null default 0 COMMENT 'comment time', 'autor' VARCHAR (45) not null default ''comment' author name ', 'IP' VARCHAR (100) not null default '''comment 'IP', 'url' VARCHAR (255) not null default '''comment' website ', 'email 'varchar (255) not null default ''' COMMENT 'mailbox ', 'agent' VARCHAR (255) not null default ''' 'comment' browser information ', 'parent _ id' int unsigned not null default 0 COMMENT 'parent id', 'status' VARCHAR (100) not null default ''comment' status ', 'Article _ id' int unsigned not null default 0 comment' COMMENT article id', primary key ('id '), INDEX 'fk _ article_comments_articleincluidx '('Article _ id' ASC) ENGINE = MyISAMCOMMENT = 'Post comment table ';
After reading the comments in the corresponding article, I use recursion to display the comments.
But now there is a problem. For example, if I display 10 Comments on one page and want to display the first page, I have read the top-level comments now. But how can I find the best response under these comments? (Because there may be many levels of replies, I have now recursively queried the database... Cough)
Reply content:
Database Structure:
Create table if not exists 'blog '. 'comments' ('id' bigint unsigned not null AUTO_INCREMENT COMMENT 'comment id', 'content' text not null comment' COMMENT content ', 'create _ time' int unsigned not null default 0 COMMENT 'comment time', 'autor' VARCHAR (45) not null default ''comment' author name ', 'IP' VARCHAR (100) not null default '''comment 'IP', 'url' VARCHAR (255) not null default '''comment' website ', 'email 'varchar (255) not null default ''' COMMENT 'mailbox ', 'agent' VARCHAR (255) not null default ''' 'comment' browser information ', 'parent _ id' int unsigned not null default 0 COMMENT 'parent id', 'status' VARCHAR (100) not null default ''comment' status ', 'Article _ id' int unsigned not null default 0 comment' COMMENT article id', primary key ('id '), INDEX 'fk _ article_comments_articleincluidx '('Article _ id' ASC) ENGINE = MyISAMCOMMENT = 'Post comment table ';
After reading the comments in the corresponding article, I use recursion to display the comments.
But now there is a problem. For example, if I display 10 Comments on one page and want to display the first page, I have read the top-level comments now. But how can I find the best response under these comments? (Because there may be many levels of replies, I have now recursively queried the database... Cough)
If three IDs are used, one is the reply object (Superior reply) id, the other is the Article id, and the other is the top-level reply id. In this way, you can use the top-level reply id to retrieve all IDs at a time, sort the floors by time, and add a field to mark the comments instead of replying to others.
In fact, it is not recommended to build so many floors, just once. Think of sf like this, comments are now, just use the @ xxx method, of course, it is not as intuitive as building
Some problems will also be caused, such as the middle floor being deleted by the Administrator...
Very good question.
There are actually many solutions to this infinite problem. The simplest but less efficient implementation method is recursion.
In actual projects, there will be no more than 10 floors of infinite buildings and references.
Therefore, when the data volume is controllable, there is no big problem.
However, only the subcomment ID is used for paging, and it is best to store the comment structure in the cache. The sorting amount in the memory is not large.
Based on the current table structure, the optimization method is to add a field, and all the subcomment IDs are connected directly using commas and other delimiters to reduce recursive queries.
The Data Types of Mysql are very simple. You can replace or use it with Redis, Mongo, PostgreSql, and oracle to simply solve the problem by storing the formatted data structure.