View Full Version : Dynamic Tables, is it a good design??

03-23-2004, 05:21 PM
Hi all

I'm about to write an app where my client wants full access creating his own presentational tables. We have some products and for each product there are some factors that should be demonstrated, like their weights, portability, battery type and ... The problem is we don't know what factors are necessary for each product. So, for a new product you might have some fields (instead of "factors" I'd rather use this term) but for another product you don't have those fields. And then for each fied my client should be able to define some sub fields. Let's say if product A (which is a MP3 Player) has a field called "Audio", then this field has some sub fields like "No. of Channels", "Frequency Range", "Line out level", "S/N Ratio" and ... . All the fields and sub fields are dynamic, which means we have no idea what they are and my client should be able to create/edit/delete them. Oh my God! This is like phpMyAdmin, huh?!

This is basically a 3 level table design. This is the first table:

MainFieldAutuNumID ProductId MainFieldName

And this is the 2nd table:

SubFieldAutuNumID MainFieldAutuNumID SubFieldName

And this is the 3rd table:

SubFieldAutuNumID SubFieldValue

Ok, I hope that I was clear till this part; but I'm also thinking about another sort of design, should we call it dynamic tables or whatever, I dunno, but it's like a tree structure. What I want to do is simple, I'm going to have a table which holds my meta information like this:

ProductId MainFieldName

When I get MainFieldName, I also ask the client to enter all the sub fields related to this main field, after I get both of them, I go and create a table in my database called MainFieldName and I put those SubFields I got as its fields! Do you understand what I'm talking about? I create this table with PHP, not that I had it created from the beginning. I think I can simulate a tree by this sturcture no matter how far my client wants to go, even if he wants to go 10 levels down, this sort of recursive structure works for him.

I think the first design (not using dynamic tables) is easier to implement, but then I was criticizing myself that hey, if you ever wanted to write something like Windows, I mean an operating system, that everything should be dynamic, then what did you do?

What is your idea? Do you think that it's better I do it the first way, or the 2nd? And why?

Thank you