|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Different stock values to different product features
Hello,
I had already posted this question in PHP related forum but I was told to post it here. They thought it was a database question... I'm developing a webstore in php, and I want to create the possibility of associating different stock values to different product features. Example: I have two t-shirts of the model A, one in green and one in white. As it is today, I can only assign a total stock ammount of 2 items (white + green). I want to have the possibility of associating a stock value for the model A white t-shirt, and another stock value to model A green t-shirt. I thought the solution was to change the php codes of the files that handle these features. But then i've been told that changing database tables would be much more easier and helpful. I have a mysql database created but I'm a total newbie concerning programming, so I'd like to request assistance from this community, if possible. Please tell me what you need to know in order to help me and I'll do it immediately. Thanks in advance. |
|
#2
|
||||
|
||||
|
ok - what you want to do is have 3 different tables - one for the product, 1 for the attributes of products and a bridge table to link the different products to the different attributes.
Ex: Code:
table1: Products id discription 1 shirt 2 pants 3 thingabob 4 domaflogy table 2: attributes id value 1 white 2 green 3 plastic 4 metal table3: Pro_to_attr product_id attr_id 1 1 1 2 2 2 3 3 3 4 make sense? with this method you can have as many attributes as you want on any given product.
__________________
life is a game.... Have fun ----------------------------- http://www.phpwomen.org strength in unity PHPCommunity IRC #phpc on freenode |
|
#3
|
|||
|
|||
|
I think it makes sense.
Can you tell me what steps should I take to insert something like that on my database? |
|
#4
|
||||
|
||||
|
you need to create the tables you need - see your DB documentation on the CREATE statement syntax
for the basics on SQL see http://sqlcourse.com/ - see what you can come up with and if you need help - let us know. |
|
#5
|
|||
|
|||
|
Quote:
Ok I'll work on that. Thanks! |
|
#6
|
|||
|
|||
|
I already have a Products table.
On it there's a Features (attributes) field. It also has a Stock field (it's working but only like a total stock, not a stock for each feature) So I can set different features to the same product. Now what I need is a table that tells me that I can have different stock values (product quantities) for different attributes of the same product. It's getting difficult to find help on this on the web... Any help on this from anyone? Thx a lot. |
|
#7
|
||||
|
||||
|
sounds like time for another table - quantities - with the product and attribute primary keys as its primary key.
normalization++ |
|
#8
|
|||
|
|||
|
Quote:
Can you tell me how to do this? I'm trying to learn but it's all too fast! Thx once more for your patience. |
|
#9
|
||||
|
||||
|
what database are you using? Assuming you are using MySQL you can do it a couple of ways.
1) add it to the CREATE statement for the table Ex: Code:
mysql> CREATE TABLE test (a INT NOT NULL AUTO_INCREMENT,
-> PRIMARY KEY (a));
2) alter the table that is already made to have it Ex: Code:
mysql> ALTER TABLE test ADD PRIMARY KEY (a); if you have more then one column that you want to be the primary key, just list the columns in the order you want comma seperated. |
|
#10
|
|||
|
|||
|
I forgot to mention that I'm working on a mysql database online, i don't have it running locally.
So I'm working through The MySQL Database Admin v1.5.5. From what see there's no need to use programming with that, there are shortcuts and buttons to work things out. I'm having some difficulty but I'm on it... |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Different stock values to different product features |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|