Menu/List trying to be dynamic or attach to an MySQL DB

Is there is trick on how to dynamically adjust a menu/list box while doing the following?

  1. from a database… as if you are having your products selected from the manu.

  2. as quantities and if the customer makes a choice to increase available quantities?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Jun 22, 2011, at 9:49 PM, Shane wrote:

Is there is trick on how to dynamically adjust a menu/list box while
doing the following?

  1. from a database… as if you are having your products selected
    from the manu.

You need to code a little. Rather than using Freeway to make a picking
list, you would create it in PHP. If you had gathered all the possible
options into an array from your database, you could iterate over that
array and dynamically build the picker. Here’s a crude example:

<?php
//you've gotten your data out of the database
//and into an array that looks like this (SKU: Name):
$options = array('1234' => 'Kumquats',
	'2345' => 'Plums',
	'3456' => 'Starfruit');
$picker = '<select name="fruit" size="1">';
foreach($options as $key => $value){
	$picker .= '<option value="' . $key . '">';
	$picker .= htmlspecialchars($value) . '</option>';
}
$picker .= '</select>';
echo $picker;
?>

So if you put all that in a Markup Item right where you expect the
“fruit” picker to be, the picker will just materialize there on the
page when you look at it from the server.

Obviously, you’d want to integrate this with your database, so you’d
need to have a query that gathered the SKU and the Name of each item
in the Fruit table, maybe sorted them by name so the list was
alphabetical. I’m not sure what the MySQL Actions can do for you
there, I haven’t used them in nearly 10 years. And if you were going
to have more than one or two of these, you’d want to roll this method
up in a function that can accept any array and turn it into a picker.

  1. as quantities and if the customer makes a choice to increase
    available quantities?

I need you to spell this one out a little more. Are you talking about
the customer clicking a button in the page and having JavaScript
insert new options into an existing picking list without refreshing
the page? Or are you talking about having a link on the page that the
customer clicks and the picking list is rewritten on the next page
reload to have additional options? Or something else?

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

On the options part. Say you are doing an E-Buy-Quanity box, and want the max or min numbers of quantify a customer could purchase to be based on a selection before.

Here is an example. A basket can only have 2 apples in it unless the customer picks the larger basket option what would allow up to 10 apples. How could you change the amount in the quantity list from 2 to 10?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

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

Walter,

I can do a simple PHP “if statement” to force an auto select of the larger basket if the customer goes above 2 apples.

force the selection and do a popup window stating what happen.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options