Skip to main content
Inspiring
September 7, 2012
Answered

adding dynamic menus

  • September 7, 2012
  • 2 replies
  • 1139 views

I am building a shopping cart the has a backend and a user end

i need in the backend to have a list of sizes that the end user will be able to select

In the backend i have an add item page

i can add the

ItemID

Title

Desc

Image

Price

but i also need to add the sizes...s,m,l,xl,xxl

and the coulours....red,blue.gree

but i need to be able to add either s,l,xl and not all of them

or red, green

then for the end user they need to see a select list so they can chose what one they want.

Am I am thinking of this too much.?

thanks in advance

This topic has been closed for replies.
Correct answer bregent

>In the backend i can manually add these using a feild for each colour or size

>but the problem i have is if there i 10 colours i need 10 feilds in the DB to handle

Yes, that's the wrong way to handle it. Your database should look more like this

ITEMS

------------

itemID

itemTitle

itemDesc

itemPrice

ITEM_DETAIL

---------------------

DetailID

ItemID

Color

Size

Photo

Availablity

The ITEM_DETAIL table stores one row for every color/size combination of an item. And this assumes that the price is the same for all colors and sizes. Otherwise, move that to the ITEM_DETAIL table.

2 replies

Participating Frequently
September 7, 2012

>but i need to be able to add either s,l,xl and not all of them

>or red, green

Do you want the backend users to select the sizes/colors from a list, or just enter those options into the field 'freehand'. Assuming the former, it's going to be a little tricky.  Example:

Say you've got a shirt that comes in Small, medium and large. Your size field would have "S/M/L". But other sizes like XL and XS are also possibilities that you might want to add in the back end. So when editing the product you first need to parse (explode) the sizes field into an array. Then in a loop create the list of all possible items and after each one, check the size array to see if it's in there and if it is, display it as selected. When saving the product, loop through all select items again and concatenate them together to store in the size field.

>then for the end user they need to see a select list so they can chose what one they want.

We already discussed this in another thread. It's a simple matter of exploding the concatenated list into an array.

>Am I am thinking of this too much.?

No, it's not really that easy to do since the data is not properly normalized. If you had another table to store the product_options, it would be a piece of cake. Now might be a good time to rethink the database design.

Inspiring
September 7, 2012

ok, i can have the sizes entered "freehand" aslong as the user had them in a select list or that sounded interesting what you said about having a table to store the product options, how would that work?

i think either one of them would do it?

Inspiring
September 7, 2012

i have tried adding a dynamic list menu but if i do that i can only select one of the sizes/colours, i need to be able to add my own in the back end (the same way paypal buttons work where you can add dropdown menu feilds