This gets fairly complicated if you also need to abstract the notion of what you can put in the basket. What I mean by this is that if you can also put pears or oranges in the basket, then you either have to say that the apples, pears, and oranges are all fruit, and that you can add 10 pieces of fruit to the basket, or maybe 10 pieces of each kind of fruit. But you can see how this gets complicated at the modeling level. It’s very easy to slip into a place where have to add a MaximumApples field to the baskets table, and have two rows, one for the small basket, with MaximumApples set to 2, and another set to 10 for the large basket. But that locks your database into a spiral of adding a column for each kind of thing you could ever add to that basket. And it doesn’t scale from a design standpoint. So then you need another table that can act as a go-between, so you can combine products into compound products, and that becomes another form of complexity altogether.
So to answer your initial question, if you need something simple, and you don’t need the flexibility to have one table of products that holds baskets AND fruit, then you just tack on a MaximumFruit column or something to the baskets table, and build your picker using the same basic method I outlined earlier. In place of the array of database records, you just use a Range, which in PHP is a special sort of array.
$maximum = $product->MaximumFruit;
$options = range(1,$maximum);
And then use the same picker constructor ad before, except there’s no need for the key and the value to be different, so you would just do
foreach($options as $option){
And then use $option in place of both $key and $value in the next lines.
This is a sort of a hack, more to make an example of how you construct the form element from the database row. There’s a much more complex way to solve this that doesn’t box you in a corner, as I mentioned at the beginning. It’s not as simple to explain, though.
Walter
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options