<分区>
好的,让我们从头开始,我们正处于需要为我们的产品创建文档的阶段。由于我们的产品是基于网络的,我打算创建一个在线文档并在每个产品上添加一份副本。
我计划的文档将使用 PHP-HTML 前端和数据库后端。
所以这是我要构建的内容:
Table of Contents
1 Getting Started
1.1 Hello World
1.2 Installing
1.2.1 Windows
1.2.2 Unix
1.2.3 Mac
1.3 Configuring
1.3.1 Windows
1.3.2 Unix
1.3.3 Mac
2 Hal
2.1 Dave
2.2 9000
....
....
这是表格。
CREATE TABLE content(
id VARCHAR(50) NOT NULL,
parentId VARCHAR(50) DEFAULT NULL,
title VARCHAR(255) NOT NULL,
message TEXT NOT NULL,
dateReg TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
FOREIGN KEY (parentId) REFERENCES `content` (id) ON DELETE CASCADE ON UPDATE CASCADE
)
请原谅语法,这只是一个模型
插入内容如下
INSERT INTO content ('1', 'Getting Started', 'Hello', NULL);
INSERT INTO content ('1.1', 'Hello World', 'cout << \"Hello World\";', NULL);
.... and so on
检索必须在 php 中完成。下面只是做一个“目录类结构”
$top_query = "SELECT * FROM content WHERE parentId IS NULL";
while($top_res = mysql_fetch_array($top_query)){
print $top_res['title'] . "\n";
$child_query = mysql_query("SELECT * FROM content WHERE parentId={$top_res['id']}");
while($child_res = mysql_fetch_array()){
print $child_res['title'] . "\n";
}
}
Now i know what you will say, it needs to be recursive, yes i know, and right now lack of sleep is so bad that i cant even spell recursive (It was auto spelt by google chrome). But recursion is not my issue, i can figure that out.
我的问题:我忍不住认为这将发送大量查询,并且数据库将让每个访问该文档的用户心脏病发作。
问题:我是否走在正确的轨道上,或者有任何人有建议使这项工作充分发挥作用并降低性能强度。
提前致谢