296 Replies - 9152 Views - Last Post: 19 March 2009 - 01:32 PM
#1
Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 28 January 2009 - 01:07 PM
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.
Thanks!
Replies To: Need help getting started - PHP, MySQL, Item/Part Configurator
#2
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 28 January 2009 - 01:49 PM
base part (ex: machine screw)
components (ex: stainless steel, linked to a group)
component groups (ex: materials)
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
#3
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 12:15 PM
<?php
// Make a MySQL Connection
include ('dbconnect.php');
$sql="SELECT * FROM stems";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$series=$row["series"];
$stems=$row["stems"];
$options.="<OPTION VALUE=\"$series\">".$stems.'</option>';
}
?>
<body>
<head>
<html>
<form name="form" method="post" action="">
<SELECT NAME=series>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
</html>
</head>
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.
#4
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 12:26 PM
#5
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:
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.
#6
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 01:06 PM
<?php
// Make a MySQL Connection
include ('dbconnect.php');
$sql=mysql_query("SELECT * FROM stems");
?>
<body>
<head>
<html>
<form name="form" method="post" action="">
<SELECT NAME=series>
<OPTION VALUE=0>Choose
<?php
while ($row=mysql_fetch_array($sql)) {
$series=$row["series"];
$stems=$row["stems"];
echo '<OPTION VALUE=\"$series\">'.$stems.'</option>';
}
?>
</SELECT>
</html>
</head>
#7
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 01:09 PM
BenignDesign, on 30 Jan, 2009 - 12:06 PM, said:
<?php
// Make a MySQL Connection
include ('dbconnect.php');
$sql=mysql_query("SELECT * FROM stems");
?>
<body>
<head>
<html>
<form name="form" method="post" action="">
<SELECT NAME=series>
<OPTION VALUE=0>Choose
<?php
while ($row=mysql_fetch_array($sql)) {
$series=$row["series"];
$stems=$row["stems"];
echo '<OPTION VALUE=\"$series\">'.$stems.'</option>';
}
?>
</SELECT>
</html>
</head>
The code I originally posted had the same output; one drop down menu with information from the table 'stems'. What logic was behind moving the while statement?
#8
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 01:12 PM
Are you absolutely certain there is more than 1 item in your table?
#9
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 01:18 PM
<?php
// Make a MySQL Connection
include ('dbconnect.php');
$sql=mysql_query("SELECT * FROM basepart");
?>
<body>
<head>
<html>
<form name="form" method="post" action="">
<SELECT NAME=series>
<OPTION VALUE=0>Choose
<?php
while ($row=mysql_fetch_array($sql)) {
$series=$row["series"];
$stems=$row["stems"];
echo '<OPTION VALUE=\"$stems\">'.$series.'</option>';
}
?>
</SELECT>
</html>
</head>
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:
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.
#10
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 01:20 PM
function ActivateDropdown(series){
if(series=="series_A"){
document.getElementById('next_dropdown').style.display='none';
}else if(series=="series_B"){
document.getElementById('next_dropdown').style.display='block';
}
}
#11
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 30 January 2009 - 01:23 PM
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.
Here's a little of how I'd fix it:
<?php
// Make a MySQL Connection
include ('dbconnect.php');
$sql="SELECT * FROM stems";
$result=mysql_query($sql);
if (!$result)
{
die("Query failed: " . mysql_error());
}
$options='';
while ($row=mysql_fetch_array($result)) {
$series=$row['series'];
$stems=$row['stems'];
$options.='<OPTION VALUE="$series">.$stems.'</option>';
}
mysql_free_result($result);
?>
<html>
<body>
<head></head>
<form name="form" method="post" action="">
<SELECT NAME="series">
<OPTION VALUE="0">Choose</OPTION>
<?php echo $options; ?>
</SELECT>
</form>
</html>
Hope this helps.
EDIT: Oops...looks like the game changed a bit while I was typing
This post has been edited by JackOfAllTrades: 30 January 2009 - 01:23 PM
#12
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:
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.
Here's a little of how I'd fix it:
<?php
// Make a MySQL Connection
include ('dbconnect.php');
$sql="SELECT * FROM stems";
$result=mysql_query($sql);
if (!$result)
{
die("Query failed: " . mysql_error());
}
$options='';
while ($row=mysql_fetch_array($result)) {
$series=$row['series'];
$stems=$row['stems'];
$options.='<OPTION VALUE="$series">.$stems.'</option>';
}
mysql_free_result($result);
?>
<html>
<body>
<head></head>
<form name="form" method="post" action="">
<SELECT NAME="series">
<OPTION VALUE="0">Choose</OPTION>
<?php echo $options; ?>
</SELECT>
</form>
</html>
Hope this helps.
EDIT: Oops...looks like the game changed a bit while I was typing
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?
Example:
Their code
//var hide_empty_list=true; //uncomment this line to hide empty selection lists
var disable_empty_list=true; //uncomment this line to disable empty selection lists
addListGroup("valves", "series");
addOption("series", "---", "", "", 1); //Empty starter option
addList("series", "100", "100", "100");
addList("series", "200", "200", "200");
addList("series", "300", "300", "300");
addOption("100", "---", "", "", 1);
addList("100", "Mini '100ST1'", "", "100ST1");
addList("100", "Packing Style '100ST2'", "", "");
addList("100", "Regulating '100ST3'", "", "");
addList("100", "Regulating Packing Style '100ST4'", "", "");
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.
Are my thoughts/explanations coming across coherently?
Thanks!
#13
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 02 February 2009 - 11:36 AM
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!!
#14
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:
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.
#15
Re: Need help getting started - PHP, MySQL, Item/Part Configurator
Posted 02 February 2009 - 12:46 PM
kiwi2, on 2 Feb, 2009 - 10:36 AM, said:
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
|
|

New Topic/Question
Reply




MultiQuote









|