Reply
Database structure for CMS
Old 10-28-2009, 06:52 AM Database structure for CMS
Novice Talker

Posts: 5
Name: Yoke
Trades: 0
Hi

I am making a CMS system for an e-shop.
The goal is client would be able to manage their own catalogue including categories and products.
I don't have any problem creating categories that has many products.
But I cant think of how to allow user configure their own product's attributes.
For example: a fashion store has color and size for their product, while others don't.

How to make the structure without duplicating the item record? all i can think of is having several records of the items with same name, price, summary, description but with different color and size (color and size column is customized, so may not be there also).

I hope everyone can understand what I'm trying to explain.
Please help me. Many thanks in advance.
yoke.lee is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 10-28-2009, 07:06 AM Re: Database structure for CMS
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Normalisation..
This is what you need.

As I understand it now, you are cramming all the attributes of an article in the same table than the article, like this:
Code:
id   name   size   color       
---------------------------
1   shirt      l       red       
2   shirt      l       blue
What you need is to normalize this table, to his simple expression, and split the informations in separate tables:
Code:
table users:
  userId integer auto_increment
  userName varchar(50)
  email varchar(50)
  ...

table article:
  articleId integer

table articleName:
  articleFk integer references article(articleId)  -- link to the article
  userfk integer refrences users(userId)           -- link to the user
  language char(2) default 'EN'
  articleName varchar(100)

table articleColors:
  articleFk integer references article(articleId)
  userfk integer refrences users(userId)
  color varchar(20)

table articleDetails:
  articleFk integer references article(articleId)
  user fk integer refrences users(userId)
  summary text
  description text
That way, what is generic is present 1 time (article)
but the attributes of those articles can be matched on a "per user" base
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-28-2009, 07:12 AM Re: Database structure for CMS
Novice Talker

Posts: 5
Name: Yoke
Trades: 0
Wow! What a swift reply!

So, are you saying that I have to make one new table per every attribute I made?
e.g. 1 table for color, 1 table for size, etc..?
does each table has their own primary key?

Then how to make the transaction/sales table?
By the time, user pick a red shirt size L, i need to link all the tables up there right?
If they don't have primary key.... I don't know how to connect them...
yoke.lee is offline
Reply With Quote
View Public Profile
 
Old 10-28-2009, 08:10 AM Re: Database structure for CMS
chrishirst's Avatar
Super Moderator

Posts: 22,225
Location: Blackpool. UK
Trades: 0
Quote:
So, are you saying that I have to make one new table per every attribute I made?
e.g. 1 table for color, 1 table for size, etc..?
does each table has their own primary key?
That would be the peak of normalisation. and yes each table has a PK or unique id for the row.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-28-2009, 09:20 AM Re: Database structure for CMS
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
If they don't have primary key.... I don't know how to connect them...
Don't you ever even think about having a table without a primary key !
Seriously, the whole goal of a rdbms (relational data base management system) is to link tables between themselves.
You need a key to do that.

What I gave you up there was "pseudo structure".
An outline of the basis of the tables, but not the complete definitions of them.
You have to extrapolate from there.

Quote:
Then how to make the transaction/sales table?
It's up to you.
In the enterprise I work for, the sales system is basically based on 2 tables.
An header table, linking to a user, a cashier, the terminal, and a transactionLines table with every articles that are included in the transaction.

Code:
table transactions:
  idsTransactionId integer
  intCustFk integer references customers(idsCustmoerId)
  intPosFk integer references terms(idsTermId)
  dtmStart datetime
  dtmEnd datetime

transactionLines:
  intTransFk integer references transactions(idsTransactionId)
  intArtNr integer references articles(idsArtId)
And a bunch of satellites table around the transaction lines that describe thew price, if there was a reduction, and if the price was partially paid by a given mean, for how much (IE: a voucher is given but doesn't cover the whole amount, and the rest have been completed by a credit card)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-29-2009, 01:00 AM Re: Database structure for CMS
Novice Talker

Posts: 5
Name: Yoke
Trades: 0
Wow! Thanks a lot for your explanation.
Since it shakes my brain a lot, let me fully explain the requirement of the system.

I attached a JPEG of the ERD sketch.

The point here:
Categories could be main categories and sub categories.
A main category can have many subcategories.
Products can only be assigned to 1 subcategory.

Additional attributes are assigned to main categories.
Therefore, the subcategories and products that fall under a main category must inherits all the attributes that assigned to that main category.

Sales table must somehow linked to products, with their additional attributes attached. Like for example:
Yoke buy 3 shirt A size S: 1 red, 2 blue.
Please see the image for explanation.

I have no problem with fixed table, but since this is a cms system, admins must be able to add/edit/delete their additional attributes to a main category.

The image is all I can think about so far... but I believe I made mistakes somewhere....
I will go on and read about normalization further.

Please please please bear with me. I have all this fog inside my head, dunno how to solve this. Thank you very very much in advance.
Attached Images
File Type: jpg attachment.jpg (46.4 KB, 0 views)
yoke.lee is offline
Reply With Quote
View Public Profile
 
Old 10-29-2009, 01:52 AM Re: Database structure for CMS
Novice Talker

Posts: 5
Name: Yoke
Trades: 0
I somehow understand what is tripy trying to explain about normalisation, here is 1NF.
I believe I have already applied that in my ERD.
But doesn't solved my problem.
The problem here is I cannot make 1 table for 1 attribute, since attributes for each main categories may not be the same.
For example, guy's shirt have color & size, but bags only have size.
And lingerie (e.g bra) may have color, size, and cup.
yoke.lee is offline
Reply With Quote
View Public Profile
 
Old 10-29-2009, 04:34 AM Re: Database structure for CMS
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Normally, I would recommand you to have 1 "attributes" table per type of article.
This to allow you to have defined properties for a type of article.

But I understand it can be tedious, and if you are cautious about it's use, why not have 1 table attributes.
I have used a structure like this:
Code:
table attributes:
  intArtId integer
  attribName varchar(100)
  strVal varchar(100)
  boolVal boolean
  intVal integer
  numVal numeric
  dtmVal datetime
This allow me to attach X attributes to 1 article, and to give it a name and a value.
I kept distinctive types fields to leverage the db optimizations on certain datatypes.
Given that you can only have 1 value for a attribute, the select would be done using coalesce():
Code:
select coalesce(strVal, boolVal, intVal, numVal, dtmVal) as value from attributes where artID=x
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-29-2009, 05:31 AM Re: Database structure for CMS
Novice Talker

Posts: 5
Name: Yoke
Trades: 0
yeah, i think i'll try this one first....
thanks alot tripy.
i think i can see the sun now. =)
yoke.lee is offline
Reply With Quote
View Public Profile
 
Old 11-07-2009, 02:32 AM Re: Database structure for CMS
Banned

Posts: 3
Name: Iftikhar
Trades: 0
Basically I'am building a really basic CMS. How would I go about create a tree like structure?

Say there are 4 main sections:

Home
About
Services
Contacts

All of which are just database records in a table, how would I amend my database so that i could add pages underneath each of those categories.

Any help would be appreciated - no time waster please that are just looking for points, it gets boring!
bizexpert is offline
Reply With Quote
View Public Profile
 
Old 11-07-2009, 04:28 AM Re: Database structure for CMS
chrishirst's Avatar
Super Moderator

Posts: 22,225
Location: Blackpool. UK
Trades: 0
Copy and paste muppet

http://answers.yahoo.com/question/in...8051308AAOJ0wp

didn't even have the sense to delete the last sentence.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Database structure for CMS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13982 seconds with 14 queries