Structure of DB for CMS ideas

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
zero477
Forum Newbie
Posts: 4
Joined: Wed Nov 23, 2011 11:17 am

Structure of DB for CMS ideas

Post by zero477 »

Hello everyone,

I have a long list of standard features of some products (90 features 1800 products) which I am integrating in a CMS. I have to elaborate a CREATE, READ and MODIFY section for the products and I was thinking of using check boxes and if statements with 90 columns in my DB for each feature. (I hope there is an easier way to do this)

Before I typed in all the features in one column and splited it with the previous functions mentioned, but it doesn't work for the modify section of the CMS.

I am trying to learn a method in which I can easily integrate this 90 standard features in the CMS. Does anyone has a good idea?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Structure of DB for CMS ideas

Post by twinedev »

One method would be to create a table of all the features, then for each product have field with a list of all the ID's for the features it has. When I have to do something like that, I store it as such:

~3~9~13~44~74~

This way if I need to search for a specific one, I can do WHERE `features` LIKE "%~13~%" to grab it.

So on the page to create an item, you would have an array of all 90 features, so you can loop through displaying them, then when you are done, take the array of ones selected and do: $features_field = '~'.implode('~').'~';

To read it back in (for display or to edit: $aryFeatures = explode('~',trim($features_field,'~'));

NOW, that being said, with how many items you have, depending on how you will be using them all, you may want to just have a third table that consists nothing of ProductID and FeatureID. Those are two simplistic ways I can think of off the top of my head.
Post Reply