'Hieratic Data of Unknown Depth' or 'How to Use Recursion'
Posted: Mon Jul 28, 2008 11:35 pm
I'm trying to use PHP to dynamically generate hieratic form elements, for an e-commerce website:
eg. When you choose "Large" in the 'size' radio group of a T-shirt order form, Javascript makes a second option appear for 'color', listing only the colors that are available for "Large" shirts.
This, in and of itself, is simple and straightforward. The challenge is, the depth of the options hierarchy is unknown at the time of programming. So there could be two options (Color, dependent on Size), or 30 options (color dependent on size, dependent on design, dependent on fabric type, dependent on fabric thickness, etc...)
There's a built in PHP class called "RecursiveIteratorIterator" that may be what I need, but there's no documentation in the PHP.net manual.
The cart already has a products table. So my idea is to create a "Dummy Product" (eg. "T-Shirt") with a flag that lets the cart know it's a dummy.
Then, once the user chooses the options, based on their choices, a real product is added to the cart (eg. "T-shirt-Large-Red-Logo 1"). Because product attributes are really just for display/usability purposes.
Here are my specific questions:
1.) Should I use the "LeftID" "RightID" method (I think this is called Nested Sets?), or the "ParentID" method, in the database for the attributes/options table?
2.) What is the appropriate way to build an array of this data, when it's depth in unknown? (recursive functions?)
Thanks,
Nick
eg. When you choose "Large" in the 'size' radio group of a T-shirt order form, Javascript makes a second option appear for 'color', listing only the colors that are available for "Large" shirts.
This, in and of itself, is simple and straightforward. The challenge is, the depth of the options hierarchy is unknown at the time of programming. So there could be two options (Color, dependent on Size), or 30 options (color dependent on size, dependent on design, dependent on fabric type, dependent on fabric thickness, etc...)
There's a built in PHP class called "RecursiveIteratorIterator" that may be what I need, but there's no documentation in the PHP.net manual.
The cart already has a products table. So my idea is to create a "Dummy Product" (eg. "T-Shirt") with a flag that lets the cart know it's a dummy.
Then, once the user chooses the options, based on their choices, a real product is added to the cart (eg. "T-shirt-Large-Red-Logo 1"). Because product attributes are really just for display/usability purposes.
Here are my specific questions:
1.) Should I use the "LeftID" "RightID" method (I think this is called Nested Sets?), or the "ParentID" method, in the database for the attributes/options table?
2.) What is the appropriate way to build an array of this data, when it's depth in unknown? (recursive functions?)
Thanks,
Nick