Need help getting started - PHP, MySQL, Item/Part Configurator

I'm having a tough time describing what I want to accomplish via a flowchart, but hopefully I can make enough sense here. Basically, I want to have a page where customers can build their own part.

First, they select the base model/part (e.g. machine screw). From there they can start selecting options: head style, material, drive style, thread size, length, etc. However, once they start choosing different options, the list of available options begins to diminish.

For example, you select a machine screw made from stainless steel. Before stainless steel was selected, you had 50 different head styles to choose from. Since stainless steel was selected, you now only have 25 to select from. So on and so forth with other options.

Once all the options/choices have been made, you wind up on a new page which explains all that you have selected, it's corresponding part number, schematic, CAD drawing, PDF catalog, etc. of that particular item you have created.

What am I looking for?

It's almost along the lines of chained selects in Javascript but I want this to be very dynamic using a single database. I would also like the options to be made from pull down menus.

I have dealt with PHP and MySQL previously but am no means an expert. I'm also not looking for someone to do the coding for me. Simple guidance is what I am looking for.

From there you'd have a link table,
ie baseToGroups
(machine screw-> materials )
(machine screw -> heads )
with possibly a third column for # of components from that group, for example you can have multiple materials for one part

Your application itself would have the first page which loads all available base parts, and selecting one would submit it

Next your php/whatever script could load a set of divs for each component you can choose from. It'd setup javascript objects linked to each div, so for example a machine screw would have a div for materials, a div for head styles, and a div for thread size. Each div would display initially all the selectable options, when one option was selected, the javascript would send an ajax request containing the currently selected parts, and then reload each other div based on the compatible components.

Once that is done, a regular submission would put together the base part and components with the PDF, CAD and whatever else

Don't know if that helps or is just confusing, the UI part of it is mostly based on what I've done before with javascript, I'm sure there are a lot of different ways to get the same result

I'm not even quite sure what some of that code means. For example, the entire 'while' statement. Why am I calling the 'series'? 'Series' is another table which is supposed to be the base part we're starting from. What should happen is to have a drop down menu of everything in the 'series' table. Click on a particular series and have another drop down menu appear with 'stems' FOR that particular 'series'. So on, and so forth.

OR

Start with a drop down menu of the 'series' and once one is selected have all the other options appear. Perhaps someone doesn't know what 'stem' they want. Maybe they only know the material or thread size and by picking those two items, it will deduce the correct stem for them. This is where I begin scratching my head.

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 30 January 2009 - 12:26 PM

Since this sounds like a homework problem, I won't flat out give you an answer, but I will give you a big hint.... if it is a dropdown you are trying to generate, your while loop is in the wrong place.

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 30 January 2009 - 01:01 PM

BenignDesign, on 30 Jan, 2009 - 11:26 AM, said:

Since this sounds like a homework problem, I won't flat out give you an answer, but I will give you a big hint.... if it is a dropdown you are trying to generate, your while loop is in the wrong place.

I wish this was a school project, but it isn't; been out of school for many moons now. We're trying to add a little flare to our company's website and having a "Build a Part"/"Item Configurator" would do just that.

It doesn't necessarily have to be a drop down menu, but I figured it would be a good start and if we decide to change the way it looks in the future, we can.

You can call me at the office if you want final validation this isn't a school project.

Once the series is selected, we need the next drop down menu to either appear or become active.

BenignDesign, on 30 Jan, 2009 - 12:12 PM, said:

My logic behind the move was very simply that what I gave you is how I do it... though I sometimes leave out the </option> tag.... I had never seen it done the way you had it written.

Are you absolutely certain there is more than 1 item in your table?

I am working with one database that currently has two tables (basepart and stems). In the end, we will have multiple tables (e.g., thread, material, connection, etc). In the basepart table, we have 15 records and in the stems table, we have 8 records.

With either script I posted, only one drop down menu appears with that table's records. Once something is selected, nothing else populates.

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 30 January 2009 - 01:20 PM

PHP is a server side language - it pays no mind to what is happening on the client side - it will run your page from start to finish without pausing for user input. You'll want to use a client-side language to accomplish what you need, most likely Javascript... something kind of like this:

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 30 January 2009 - 01:23 PM

OK, the while statement seen here is very important to the PHP-MySQL DB interaction.

By making a SELECT query to the database you've retrieved a bunch of rows into the result set. What the while loop is doing is traversing the list of rows in the result set one at a time and with the resulting data being in PHP's standard collection, the associative array, and the array index being the column name.

Now, I can see here you've got at least two columns in the stems table, "stems" and "series". The series column looks to be the index into the series table for that stem, and stems seems to be a descriptive field for the stem. In the while loop you're constructing a string containing all the stems in the table. The displayed value in the dropdown is the value from the stems field, and the actual value that is important is the value of the OPTION html tag, which is the value in the series field.

FYI: You need to close your form </form> after the </SELECT>, you need fix the head closing tag (should likely have long before been closed), and I'm assuming you'll want a button to actually submit the form (at least to begin with...you can conceivably get fancier with Javascript).

Now, when you click that button, the page that receives the action will contain the value of the series in $_POST['series'], and you'll probably want to do another query on the database based on that piece of data.

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 02 February 2009 - 07:33 AM

JackOfAllTrades, on 30 Jan, 2009 - 12:23 PM, said:

OK, the while statement seen here is very important to the PHP-MySQL DB interaction.

By making a SELECT query to the database you've retrieved a bunch of rows into the result set. What the while loop is doing is traversing the list of rows in the result set one at a time and with the resulting data being in PHP's standard collection, the associative array, and the array index being the column name.

Now, I can see here you've got at least two columns in the stems table, "stems" and "series". The series column looks to be the index into the series table for that stem, and stems seems to be a descriptive field for the stem. In the while loop you're constructing a string containing all the stems in the table. The displayed value in the dropdown is the value from the stems field, and the actual value that is important is the value of the OPTION html tag, which is the value in the series field.

FYI: You need to close your form </form> after the </SELECT>, you need fix the head closing tag (should likely have long before been closed), and I'm assuming you'll want a button to actually submit the form (at least to begin with...you can conceivably get fancier with Javascript).

Now, when you click that button, the page that receives the action will contain the value of the series in $_POST['series'], and you'll probably want to do another query on the database based on that piece of data.

Actually, I only have two tables (stems and series) with one column each; stems and series respectively. Because of the various components that can go into building one part, I thought this was the best way to go. I wouldn't know where to begin sorting all the different components if I only used one table with multiple columns.

Second, I tried your above code and after filling in the missing code, there was no output (no menu) and no errors. ?

Third, I understand that when a user selects something from the drop down menu that it will take client side javascript to produce the next round of drop down menus. The code I found for chained selects is from http://www.dynamicdr...lects/index.htm

Their code requires me to hard code all of the variables and possible configurations. How would I be able to use that code but instead of calling out the values for the menu within the javascript code, call out the values from our database tables?

In that code, I am manually entering the first menu group "series". The pull down menu consists of ---, 100, 200, and 300 choices. If '100' is selected, the next menu populates with ---, Mini '100ST1', Packing Style, etc.

Although this is really close to what I want to accomplish, it doesn't leave too much room for user options. Meaning, the user first picks the series, then the user must pick the stem, and so on and so forth. I want the user to be able to start wherever they like because every user will not know exactly what they want. Example, they know they want a 100 series made from stainless steel but they have absolutely no idea what stem to pick. So essentially, picking the stem should be the last thing they need to do. And by the time they have picked all the other options, the stem selections will have narrowed down significantly.

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 02 February 2009 - 11:36 AM

everyone has done a lot of work on this one.
1. u can't knit bits of code u don't understand to get a workable result.
2. The most NB part to mysql is table design, spend a little time on working out what u need in plain english, then design your tables around that logic.
3.Don't get carried away with one complicted option, the fireworks will come naturally once you have sorted the basic design.
4. U say u wish to build this yourself, good.. now get expert help ..., go to http://www.melonfire.com, and if u can't build it from there buy the book, believe me u won't go wrong!!

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

Posted 02 February 2009 - 12:01 PM

kiwi2, on 2 Feb, 2009 - 10:36 AM, said:

everyone has done a lot of work on this one.
1. u can't knit bits of code u don't understand to get a workable result.
2. The most NB part to mysql is table design, spend a little time on working out what u need in plain english, then design your tables around that logic.
3.Don't get carried away with one complicted option, the fireworks will come naturally once you have sorted the basic design.
4. U say u wish to build this yourself, good.. now get expert help ..., go to http://www.melonfire.com, and if u can't build it from there buy the book, believe me u won't go wrong!!

Yes, I'm in the process of just putting everything in words. If I start with this, I have these options, and if I select this, I now have these options...so on and so forth.

Re: Need help getting started - PHP, MySQL, Item/Part Configurator

4. U say u wish to build this yourself, good.. now get expert help ..., go to http://www.melonfire.com, and if u can't build it from there buy the book, believe me u won't go wrong!!

WTH is with the random advertising? This isn't the place to spam people that are looking for programming help.

noboost4you: Since this is getting pretty specific with regards to what specific code you need, it would help if you posted the structure of the tables you are using. In your first post, I responded assuming you were able to design the tables from scratch, and therefore enforce a good design to work with. If you have to use two existing tables, then post what their fields look like.

The example javascript you found is part of what you need, but not the whole thing. You'd need your php code to generate the javascript code which loads the select groups