我正在构建一个用于编辑页面内容的CMS。我希望尽可能灵活,因为每个页面将包含可变数量的部分。CMS的数据库结构
目前,我有以下几点:
Table page:
===========
id
name
Table page_section:
===================
id
page_id
name
display_order
Table page_section_sub:
=======================
id
page_section_id
name
content
我认为这种结构将很好地工作,直到我意识到有很多重复的数据,它不是拉选择特定的数据的理想方式。
例如,表page_section_sub
中的name
字段用于存储表单的字段标签。下面是一个示例数据:
Table page_section:
===================
id page_id name
-----------------------------------------
1 1 Slideshow Slide 1
2 1 Slideshow Slide 2
3 1 Slideshow Slide 3
4 1 Middle Box
5 1 Bottom Box
Table page_section_sub:
=======================
id page_section_id name content
------------------------------------------------------
1 1 Heading ...
2 1 First Paragraph ...
3 1 Second Paragraph ...
4 2 Heading ...
5 2 First Paragraph ...
6 2 Second Paragraph ...
7 3 Heading ...
8 3 First Paragraph ...
9 3 Second Paragraph ...
10 4 Image URL ...
11 5 Image URL ...
现在在前端我想显示的3张幻灯片和其从上述表中的相关content
。这证明是非常乏味的。
我知道我可以为“标题”,“第一段”和“第二段”创建另一个带有单独列的表,但正如我所提到的,我需要这个系统是灵活的,并考虑到任意数量的列。
如何改进此数据库的结构,以便我可以轻松地在前端输出此数据并在后端修改它?
编辑:这是我想在我面前做到底:
<?php while($row = mysql_fetch_array($slideshow)) { ?>
<div class="slideshow">
<h1><?php echo $row['heading']; ?></h1>
<p class="first"><?php echo $row['first']; ?></p>
<p class="second"><?php echo $row['second']; ?></p>
</div>
<?php } ?>
但当然这些实际$行的列不存在于表中。在后端的,但是我需要能够在一页上编辑上述11行。
只是一个提示......你可能想看看非关系型数据库,如mongo db,因为它提供了极高的速度和灵活性......你的内容应该适合它。 – jribeiro 2012-01-06 12:08:23