I am building a CMS for editing page content. I would like to make it as flexible as possible, as each page will contain a variable amount of sections.
Currently, I have the following:
Table page:
===========
id
name
Table page_section:
===================
id
page_id
name
display_order
Table page_section_sub:
=======================
id
page_section_id
name
content
I thought this structure would work well, until I realised there is a lot of repetitive data and it’s not the ideal way to pull specific data out.
For example, the name field in table page_section_sub is meant to store the field label for the form. Here is a sample data:
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 ...
Now on the front end I want to display the 3 slideshows and their related content from the above table. This is proving to be very tedious.
I know I can create another table with separate columns for “Heading”, “First Paragraph” and “Second Paragraph”, but as I mentioned I need this system to be flexible and take in to account any number of columns.
How can I improve the structure of this database so I can easily output this data on the front end and also modify it on the back end?
EDIT: This is what I want to do in my front end:
<?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 } ?>
But of course those actual $row columns don’t exist in the table.. In the back end however I need to be able to edit the above 11 rows on one page.
From your description it would seem like you could do it with just ‘pages’ and ‘content’. Im not sure why you have the ‘section_sub’.
Each content row could have columns for “show heading”, “font”, etc
EDIT: example data
Now that Im looking at this – the way I have at the top (with multiple ContentID sections in the Page table) – is more of a NoSQL solution. You can accomplish the same thing in a MySQL solution by adding a table as follows:
Entries to build a specific page would be like:
To build a specific page you’d select for the PageId joined to the PageContent then joined to the Content itself and order by PageOrder.