4

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.

1
  • 1
    Just a tip... You might want to look at non relational databases like mongo db given it provides you extreme speed and flexibility... Your content should be suited for it. Commented Jan 6, 2012 at 12:08

1 Answer 1

4

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'.

pages: 
   Page ID
   Content ID
   Content ID
   Content ID
   ...

Content:
   Content ID
   Content Heading
   Content Text

Each content row could have columns for "show heading", "font", etc

EDIT: example data

Content:
    ID0, Slide0 header, slide0 text
    ID1, Slide1 header, slide1 text
    ID2, Slide2 header, slide2 text
    ID3, RepetitiveHeader0, RepetitiveText0
    ID4, Repetitiveheader1, RepetitiveText1
    ID5, RepetitiveHeader2, RepetitiveText2

 Pages:
    Page0, Title0
    Page1, Title1
    Page2, Title2

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:

  PageContent:
    PageID
    ContentID
    PageOrder

Entries to build a specific page would be like:

  Page0, ContentID0, (order)1
  Page0, ContentID3, (order)2
  Page0, ContentID4, (order)3
  Page1, ContentID1, (order)1
  Page1, ContentID4, (order)2
  Page1, ContentID5, (order)3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi ethrbunny, thanks for your reply. Could you provide an example of how this will work? (using my sample data)
Cheers, I will give this a try and let u know how it goes :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.