Jump to content

Recommended Posts

Ok... I'm starting from scratch. I know there's an easier way to do what I want to do, but I dove in head-first with an empty pool of knowledge on this apparently. So, starting from the beginning, how would I go about doing this. I think it's probably easier than I've made it. Everything about my current code is broken/ inneficent.

 

I want to build a page where t customer builds their own product from different components. After they choose option A1 or A2, the page reloads, or a div shows that lists the B options available to what they picked, after that, they get the C choice they made. And so on.

 

As they make each choice in the form, I also want to give them a running list of their choices to the side: I.E. "you have chosen: A: 2, B: 5, C: 1, etc.

 

 

I have three main tables that they're working from:

 

1. component_categories: the different categories of items - essentially  A, B, C, D as shown above.

2. Components: the 1 or 2 or 3, etcetera.

3. I also have a many-to-many link table, components_to_components, that lists the component id, and then the compatible component id. for example:

 

A1 is compatible with B2

A1 is compatible with B4

A2 is compatible with B2

A2 is compatible with B3

 

B2 is compatible with C3 and so on.

 

 

A loose outline, anything would help. I can post what I have right now, but it's such a confusing mess and I'd really like to start over from scratch with the simplest, most elegant solution, so I know how to do this for the future. How would you build such a section?

 

If I were you, and knowing loosely what you want, I think I'd do it in a manner similar to this one:

// Check if something has been posted.
if (!empty ($_POST)) {
// Validate options selected, and return an associative array with the selections.
$selected = fetch_options ($_POST);

// Retrieve the available options, based upon what's previously selected.
$available = $db->query ('SELECT * WHERE $selected');

// Create a drop-down list for each category, from the results of the query.
// Last parameter is used to set the default value, if something has been selected.
create_dropdown ('option_list_1', $available['options_1'], $selected['option_1']);
create_dropdown ('option_list_2', $available['options_2'], $selected['option_2']);
create_dropdown ('option_list_3', $available['options_3'], $selected['option_3']);

// Add the breadcrumb trail for the selection.
$template->addCrumb ($selected);

// Create the DIV with the finished product details.
$template->addProduct ($selected);
}

// Show the form with the drop-down lists.
$template->showForm ();

 

Should give you something to think about, at least. ;)

 

Sorry about the long reply time, by the way. Your question is quite expansive and rather open ended, so needed to mull it over a bit.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.