Solved

A real challenge... 6 step dynamic menu with corresponding dynamic reults box... HELP!! :)

Posted on 2004-04-04
82
549 Views
Last Modified: 2013-12-12
Hi Everyone,

I am a newbie to php and mysql and I am trying desperately to create a dynamic product search page.

It's a 6 step search menu, where first drop-down menu selection affects the second drop-down menu selection affects the third and so on (All of the menus items/arrays if nec. need to be database driven)...

My menu items are as follows: Product Line/ Capacity / Thread / Style / Material / Color

In addition I need to show the results of the search (which will also be pulled from the same database) in a list box on the right.

For example: If the user selects Plastic Jars from the Product Line menu, the Capacity Menu will then update to show all of the capacities that are available for plastic jars. In addition, the list box on the right will show a brief description of all of the Plastic Jars offered (one line per jar). The user will then have the option to narrow the search futher using the menu on the left or choose the items they are looking for from directly from the list box on the right. The list box items need to be somehow linked so that after a user makes there selection and presses the view products button it takes them to a summary page where the information that they have chosen is expanded upon with a pix etc. Like a product cataolg...

The way that my database is currently set up, the description that needs to appear in the results box is a combination of several fields in the same table. Is this a problem or do I need to create an additional field called description?

I can figure out how to make the drop down fields work using static arrays and the onchange () function, but I can not for the life of me figure out how to incorporate :

echo("<SELECT name=\"PRODLINE\"><option>\n");

$resultset = mysql_query("select * from Jars") or die(mysql_error());
while($event = mysql_fetch_array($resultset))
{
echo("<option value=\"".$event['PRODLINE']."\">".$event['PRODLIN']."\n");
}
echo("</select>\n");

?>

into to the onchange () command so that it all works dynamically. I also don't know how to combine fields in a table to come up with a new variable 'Description'

I hope this all makes sense?!?! :)  I would REALLY appreciate any help you could give me!!!!!!!!!!! :/ Thank you so much!

~k


My Table Structure (if it's important) is:

Product Line: Product Line / Product Line ID
Capacity: Capacity / Capacity ID
Thread: Thread / Thread ID
Style: Style / Style ID
Material: Material / Material ID
Color: Color / Color ID
Products: Product Line ID/Capacity ID/Style ID/Material ID/Item/Prodline/capacity/thread/style/material/color/unit cost/cost under 10M/cost 10- 25M etc....
0
Comment
Question by:Kristina5
  • 47
  • 35
82 Comments
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
are you wanting to populate the drop down boxes with php? if so you will have to reload the page each time using onChange() function. if you dont want to reload page each time then you will have to load everything at the beginning into javascript arrays.
which method do u prefer?
0
 

Author Comment

by:Kristina5
Comment Utility
I would like to use javascript so that I don't have to reload the page everytime, but is there a way to build the javascript arrays dynamically?
0
 

Author Comment

by:Kristina5
Comment Utility
ps - thanks!! :)
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
yes you can use php to create the javascript arrays.
something like this.... (untested though)
<?php
   $phpArray = array('item1','item2','item2');
   print "<script language=\"JavaScript\">";
   print "var myArray = new Array();";
   for ($i = 0; $i < count(phpArray);  $i++) {
         print "myArray[$i] = $phpArray[$i];";
   }
   print "</script>";
?>
0
 

Author Comment

by:Kristina5
Comment Utility
Thank you. Here is the code i already have based on this UltraDev TechNote I found : http://www.macromedia.com/support/ultradev/ts/documents/client_dynamic_listbox.htm that I found. I tried the above on my own but couldn't get it to work - probably my fault. Anyway, I can't seem to get it to work. (At the moment I am just focusing on the first parent child relationship.) What am I missing? I think it may have something to do with the queries that I have set up or maybe my relationships are wrong? Can you help me, maybe highlight what needs changing and how to change it. thanks.


<?php require_once('Connections/krdesign4ucom.php'); ?>
<?php
mysql_select_db($database_krdesign4ucom, $krdesign4ucom);
$query_ProdLine = "SELECT * FROM Jars GROUP BY 'PRODLINE'";
$ProdLine = mysql_query($query_ProdLine, $krdesign4ucom) or die(mysql_error());
$row_ProdLine = mysql_fetch_assoc($ProdLine);
$totalRows_ProdLine = mysql_num_rows($ProdLine);

mysql_select_db($database_krdesign4ucom, $krdesign4ucom);
$query_Capacity = "SELECT  * FROM Jars GROUP BY capacity ORDER BY CAPACITY ASC";
$Capacity = mysql_query($query_Capacity, $krdesign4ucom) or die(mysql_error());
$row_Capacity = mysql_fetch_assoc($Capacity);
$totalRows_Capacity = mysql_num_rows($Capacity);

mysql_select_db($database_krdesign4ucom, $krdesign4ucom);
$query_Thread = "SELECT * FROM Jars GROUP BY THREAD ORDER BY THREAD ASC";
$Thread = mysql_query($query_Thread, $krdesign4ucom) or die(mysql_error());
$row_Thread = mysql_fetch_assoc($Thread);
$totalRows_Thread = mysql_num_rows($Thread);

mysql_select_db($database_krdesign4ucom, $krdesign4ucom);
$query_Style = "SELECT * FROM Jars GROUP BY STYLE ORDER BY STYLE ASC";
$Style = mysql_query($query_Style, $krdesign4ucom) or die(mysql_error());
$row_Style = mysql_fetch_assoc($Style);
$totalRows_Style = mysql_num_rows($Style);

mysql_select_db($database_krdesign4ucom, $krdesign4ucom);
$query_Material = "SELECT * FROM Jars GROUP BY material ORDER BY material ASC";
$Material = mysql_query($query_Material, $krdesign4ucom) or die(mysql_error());
$row_Material = mysql_fetch_assoc($Material);
$totalRows_Material = mysql_num_rows($Material);

mysql_select_db($database_krdesign4ucom, $krdesign4ucom);
$query_Color = "SELECT * FROM Jars GROUP BY color ORDER BY color ASC";
$Color = mysql_query($query_Color, $krdesign4ucom) or die(mysql_error());
$row_Color = mysql_fetch_assoc($Color);
$totalRows_Color = mysql_num_rows($Color);

?>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Dynamic Dependent List box Code for *** JavaScript *** Server Model //-->
<script language="JavaScript">
<!--

var arrDynaList = new Array();
var arrDL1 = new Array();

arrDL1[1] = "prodline";               // Name of parent list box
arrDL1[2] = "form1";                  // Name of form containing parent list box
arrDL1[3] = "capacity";               // Name of child list box
arrDL1[4] = "form1";                  // Name of form containing child list box
arrDL1[5] = arrDynaList;

<%
var txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS;

txtDynaListRelation = "prodline"      // Name of recordset field relating to parent
txtDynaListLabel = "capacity"            // Name of recordset field for child Item Label
txtDynaListValue = "capacity"            // Name of recordset field for child Value
oDynaListRS = capacity                 // Name of child list box recordset

var varDynaList = -1;
var varMaxWidth = "1";
var varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value;
var varCheckLength = 0;
var varMaxLength = 0;

while (!oDynaListRS.EOF){

 if (varCheckGroup != oDynaListRS.Fields.Item(txtDynaListRelation).Value) {
  varMaxLength = Math.max(varCheckLength, varMaxLength)
  varCheckLength = 0;
 }
%>
 arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>";
 arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>";
 arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>";
<%

 if (oDynaListRS.Fields.Item(txtDynaListLabel).Value.length > varMaxWidth.length) {
  varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value;
 }
 varCheckLength = varCheckLength + 1;
 varDynaList = varDynaList + 3;
 oDynaListRS.MoveNext();
}
varMaxLength = Math.max(varCheckLength, varMaxLength)
%>


//-->
</script>

<!-- End of object/array definitions, beginning of generic functions -->

<script language="JavaScript">
<!--
function setDynaList(arrDL){

 var oList1 = document.forms[arrDL[2]].elements[arrDL[1]]
 var oList2 = document.forms[arrDL[4]].elements[arrDL[3]]
 var arrList = arrDL[5]
 
 clearDynaList(oList2);
 
 if (oList1.selectedIndex == -1){
  oList1.selectedIndex = 0;
 }

 populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
 return true;
}
 
function clearDynaList(oList){

 for (var i = oList.options.length; i >= 0; i--){
  oList.options[i] = null;
 }
 
 oList.selectedIndex = -1;
}
 
function populateDynaList(oList, nIndex, aArray){

 for (var i = 0; i < aArray.length; i= i + 3){
  if (aArray[i] == nIndex){
   oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
  }
 }

 if (oList.options.length == 0){
  oList.options[oList.options.length] = new Option("[none available]",0);
 }
 
 oList.selectedIndex = 0;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>
</head>

<body onLoad="MM_callJS('setDynaList(arrDL1)')">
<p><br>
</p>
<form name="form1" method="post" action="">
  <p>Step 1: Select Product Line<br>
    <select name="prodline" id="prodline" onChange="MM_callJS('setDynaList(arrDL1)')">
      <?php
do {  
?>
      <option value="<?php echo $row_ProdLine['PRODLINE']?>"<?php if (!(strcmp($row_ProdLine['PRODLINE'], $row_ProdLine['PRODLINE']))) {echo "SELECTED";} ?>><?php echo $row_ProdLine['PRODLINE']?></option>
      <?php
} while ($row_ProdLine = mysql_fetch_assoc($ProdLine));
  $rows = mysql_num_rows($ProdLine);
  if($rows > 0) {
      mysql_data_seek($ProdLine, 0);
        $row_ProdLine = mysql_fetch_assoc($ProdLine);
  }
?>
    </select>
  </p>
  <p>Step 2: Select a Capacity<br>
    <select name="capacity">
<%
for (varLoopCounter = 1; varLoopCounter <= varMaxLength; varLoopCounter++){
%>
 <option value = "<%=varMaxWidth%>"><%=varMaxWidth%></option>
<%
}
%>
</select>


  </p>
  <p>Step 3: Select a Thread Size<br>
    <select name="thread" id="thread">
    </select>
  </p>
  <p>Step 4: Choose a Style<br>
    <select name="style" id="style">
    </select>
  </p>
  <p>Step 5: Choose a Material<br>
    <select name="material" id="material">
    </select>
  </p>
  <p>Step 6: Select a Color<br>
    <select name="color" id="color">
    </select>
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($ProdLine);

mysql_free_result($Capacity);

mysql_free_result($Thread);
?>

0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
ok i dont know much about that ultradev thing but its looks complex :S

well from look at your queries im a bit confused.
each time you select * but from the looks of it you only need one thing at a time?
or you could just do one query. but for now we will go with the seperate queries.
i will show an example for one query and you will be able to copy for the rest of them ok?

so query1 : select a product line
$query = "SELECT prodline FROM Jars";
$result = mysql_query($query, $krdesign4ucom) or die(mysql_error());
$prodlineArray = array();
while ($row = mysql_fetch_row($result) {
      array_push($prodlineArray,$row[0]);
}

// now the html/javascript/php part
<form name="form1" method="post" action="">
<p>Step 1: Select Product Line<br>
<select name="prodline" onChange="updateCapacity();">
<?php
$arrSize = count($prodlineArray);
for ($i= 0; $i < $arrSize; $i++) {
?>
     <option value="<?=$prodlineArray[$i]?>"><?=$prodlineArray[$i]?></option>
<?php
}
?>
</select>
</form>

// ok now the trickier bit
// the code i gave you before will generate javascript arrays

before i go on though i need to know what the difference of selecting an option
in the first select box will do to the second box. how will it be populate different?
as you will need to write code that works out what belongs in the second box depending on what was selected in the first box?
0
 

Author Comment

by:Kristina5
Comment Utility
ok... I am sure this is the part I messed up.

At the moment I am working with one table - the jars table in the product database

the primary key is ITEM (it's the item sku number)

every row is all the information relating to one ITEM

The fields in my Jars table that I am primarily concerned with for the moment (however they are not the only fields in the table - if that matters).:

Product Line and Thread will actually determine the Capacity, Style, Material and Colors available for each product.

Fields:
Prodine (Jars, Caps, Wax Containers etc. - every product has a 'prodline' or 'product catagory'. Once a cust selects a product line I want the user to select from the list of available capacities... problem I have and don't know how to deal with though is not every product has a 'capacity' so the 'thread' menu must also be based on the product line selection and not the capacity selection. I have been asked to show the drop-downs in the order however because most people have a better idea of the capacity of the jar they are looking for than it's thread size. However, of course not all jar capacity have all thread sizes available. Ugh! Hope this makes sense!! Is there away to remedy this all? I think the answer is create a relational database and I have done this, but I am still not sure that I have all the nec. fields created and the select states became more complicated so I thought I would stick to using my original flat file for the momement if possible :) )
Capacity (for Jars and Wax Containers ONLY - ex: 1oz, 2oz, 3oz etc  - this is actually dependant on 'Prodline' and 'Thread')
Thread (every product has a thread size -ex: 33mm, 43mm, 48mm etc. - Thread, Product Line and in the case of jars and wax containers Capacity will determin Style, Material and Colors available)
Style (every product has a style - ex: Regular Wall, Thick Wall etc.)
Material (every product has a material - ex: Polypro, Styrene)
Color (every product has a color - this is actually dependant on 'Prodline' and 'Thread')


So, I guess I really need all of the menus to be dependent on the first select or product catagory. Not on eachother.

Lastly simaltaneously at each step of the way I would like to create a new variable on the page called 'Desc' which would be a concat of all of the above fields. This variable would be diesplayed in a list box to the right of the menu, the selections changing as the menu selections change. You can see an example of the page I modeled this after here: http://www.necvisualsystems.com/applicationFiles/productSearch/productSearch.cfm

Sorry I know this is complicated. Did that answer your question?
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
i have done something similar but i dont have the code on me at the moment but will this afternoon.

relational db sounds good idea.

what i think you will have to do is create javascript arrays for each possible path through the select menus.

you can make associative arrays in javascript  like so

myArray['prod1'] = new Array('capacity1','capacity2');
myArray['prod2'] = new Array('capacity1','capacity2');

etc







0
 

Author Comment

by:Kristina5
Comment Utility
ok great. thanks!
I will try that and see what happens. Talk to you this afternoon.

~k
0
 

Author Comment

by:Kristina5
Comment Utility
Hi I was wondering if you brought that code you were telling me about with you today. I am soooo close I can feel it... but yet still so far away! SO FRUSTRATING!! :)

I was able to produce to dynamic independant list boxes based on the code you gave me but can't figure out how to incorporate the arrays in the code so that the arrays are dynamic and the list boxes become dependent. I also can't figure out how to specify one value for the select box value and a different value for the select box label. Here is my code thus far:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
$db=mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("$database");

$queryCatagory = "SELECT prodline, prodlineID FROM tbCatagory";
$result = mysql_query($queryCatagory, $db) or die(mysql_error());
$prodlineArray = array();
while ($row = mysql_fetch_row($result)) {
      array_push($prodlineArray,$row[0]);
}
$queryCapacity = "SELECT capacity FROM tbCatagory, tbCapacity where tbCatagory.prodlineID = tbCapacity.prodlineID ";
$result = mysql_query($queryCapacity, $db) or die(mysql_error());
$capacityArray = array();
while ($row = mysql_fetch_row($result)) {
      array_push($capacityArray,$row[0]);
}
?>
</head>

<body>
<form name="form1" method="post" action="">
<p>Step 1: Select Product Line<br>
<select name="prodline" onChange="updateCapacity();">
<?php
$arrSize = count($prodlineArray);
for ($i= 0; $i < $arrSize; $i++) {
?>
     <option value="<?=$prodlineArray[$i]?>"><?=$prodlineArray[$i]?></option>
<?php
}
?>
</select>

<p>Step 2: Choose a Capacity<br>
<select name="capacity" onChange="updateThread();">
<?php
$arrSize = count($capacityArray);
for ($i= 0; $i < $arrSize; $i++) {
?>
     <option value="<?=$capacityArray[$i]?>"><?=$capacityArray[$i]?></option>
<?php
}
?>
<?php
$arrSize = count($capacityArray);
for ($i= 0; $i < $arrSize; $i++) {
?>
     <option value="<?=$capacityArray[$i]?>"><?=$capacityArray[$i]?></option>
<?php
}
?>
</select>
</form>
</body>
</html>

I also came across something called JSRS?! Ever heard of it and tried playing around with that. The first box is pulling from the database and the second appears to be dependent on the first but it isn't pulling any info from the database?!

here is the code for that:

select.php

<html>
<head>
  <title>JSRS Select Demo</title>
  <script language="javascript" src="jsrsClient.js"></script>
  <script language="javascript" src="selectphp.js"></script>
</head>

<body bgcolor="#dddddd" onload="body_onLoad();" onhelp="jsrsDebugInfo();return false;">
<h2>JSRS Select Box Filling Demo</h2>
<form name="QForm">
<table class="normal" width="575" BORDER="0" CELLSPACING="2" CELLPADDING="2" VALIGN="TOP">
<?php
  SelectBox ("Catagory",    "lstCatagory");    
  SelectBox ("Capacity",   "lstCapacity");    
  SelectBox ("Thread", "lstThread");
  SelectBox ("Style",    "lstStyle");    
  SelectBox ("Material",   "lstMaterial");    
  SelectBox ("Color", "lstColor");  
?>
</table>
</form>

<p>
  Make your selections.  Dependent selections will be filled with data from the server.  
  Change selections and dependencies will change.
</p>
</body>
</html>
<?php

function SelectBox( $Label, $selectName ){
  ?>
  <tr ALIGN="LEFT">
    <td width="15%"><?php echo $Label ?></td>
    <td align="left">
      <select name="<?php echo $selectName ?>">
        <option></option><option></option><option></option>
        <option>--------- Not Yet Loaded ---------</option>
      </select>
    </td>
  </tr>
<?php
}
?>




jsrsClient.js


//
//  jsrsClient.js - javascript remote scripting client include
//  
//  Author:  Brent Ashley [jsrs@megahuge.com]
//
//  make asynchronous remote calls to server without client page refresh
//
//  see license.txt for copyright and license information

/*
see history.txt for full history
2.0  26 Jul 2001 - added POST capability for IE/MOZ
*/

// callback pool needs global scope
var jsrsContextPoolSize = 0;
var jsrsContextMaxPool = 10;
var jsrsContextPool = new Array();
var jsrsBrowser = jsrsBrowserSniff();
var jsrsPOST = true;

// constructor for context object
function jsrsContextObj( contextID ){
 
  // properties
  this.id = contextID;
  this.busy = true;
  this.callback = null;
  this.container = contextCreateContainer( contextID );
 
  // methods
  this.GET = contextGET;
  this.POST = contextPOST;
  this.getPayload = contextGetPayload;
  this.setVisibility = contextSetVisibility;
}

//  method functions are not privately scoped
//  because Netscape's debugger chokes on private functions
function contextCreateContainer( containerName ){
  // creates hidden container to receive server data
  var container;
  switch( jsrsBrowser ) {
    case 'NS':
      container = new Layer(100);
      container.name = containerName;
      container.visibility = 'hidden';
      container.clip.width = 100;
      container.clip.height = 100;
      break;
   
    case 'IE':
      document.body.insertAdjacentHTML( "afterBegin", '<span id="SPAN' + containerName + '"></span>' );
      var span = document.all( "SPAN" + containerName );
      var html = '<iframe name="' + containerName + '" src=""></iframe>';
      span.innerHTML = html;
      span.style.display = 'none';
      container = window.frames[ containerName ];
      break;
     
    case 'MOZ':  
      var span = document.createElement('SPAN');
      span.id = "SPAN" + containerName;
      document.body.appendChild( span );
      var iframe = document.createElement('IFRAME');
      iframe.name = containerName;
      span.appendChild( iframe );
      container = iframe;
      break;
  }
  return container;
}

function contextPOST( rsPage, func, parms ){

  var d = new Date();
  var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
  var doc = (jsrsBrowser == "IE" ) ? this.container.document : this.container.contentDocument;
  doc.open();
  doc.write('<html><body>');
  doc.write('<form name="jsrsForm" method="post" target="" ');
  doc.write(' action="' + rsPage + '?U=' + unique + '">');
  doc.write('<input type="hidden" name="C" value="' + this.id + '">');

  // func and parms are optional
  if (func != null){
  doc.write('<input type="hidden" name="F" value="' + func + '">');

    if (parms != null){
      if (typeof(parms) == "string"){
        // single parameter
        doc.write( '<input type="hidden" name="P0" '
                 + 'value="[' + jsrsEscapeQQ(parms) + ']">');
      } else {
        // assume parms is array of strings
        for( var i=0; i < parms.length; i++ ){
          doc.write( '<input type="hidden" name="P' + i + '" '
                   + 'value="[' + jsrsEscapeQQ(parms[i]) + ']">');
        }
      } // parm type
    } // parms
  } // func

  doc.write('</form></body></html>');
  doc.close();
  doc.forms['jsrsForm'].submit();
}

function contextGET( rsPage, func, parms ){

  // build URL to call
  var URL = rsPage;

  // always send context
  URL += "?C=" + this.id;

  // func and parms are optional
  if (func != null){
    URL += "&F=" + escape(func);

    if (parms != null){
      if (typeof(parms) == "string"){
        // single parameter
        URL += "&P0=[" + escape(parms+'') + "]";
      } else {
        // assume parms is array of strings
        for( var i=0; i < parms.length; i++ ){
          URL += "&P" + i + "=[" + escape(parms[i]+'') + "]";
        }
      } // parm type
    } // parms
  } // func

  // unique string to defeat cache
  var d = new Date();
  URL += "&U=" + d.getTime();
 
  // make the call
  switch( jsrsBrowser ) {
    case 'NS':
      this.container.src = URL;
      break;
    case 'IE':
      this.container.document.location.replace(URL);
      break;
    case 'MOZ':
      this.container.src = '';
      this.container.src = URL;
      break;
  }  
 
}

function contextGetPayload(){
  switch( jsrsBrowser ) {
    case 'NS':
      return this.container.document.forms['jsrs_Form'].elements['jsrs_Payload'].value;
    case 'IE':
      return this.container.document.forms['jsrs_Form']['jsrs_Payload'].value;
    case 'MOZ':
      return window.frames[this.container.name].document.forms['jsrs_Form']['jsrs_Payload'].value;
  }  
}

function contextSetVisibility( vis ){
  switch( jsrsBrowser ) {
    case 'NS':
      this.container.visibility = (vis)? 'show' : 'hidden';
      break;
    case 'IE':
      document.all("SPAN" + this.id ).style.display = (vis)? '' : 'none';
      break;
    case 'MOZ':
      document.getElementById("SPAN" + this.id).style.visibility = (vis)? '' : 'hidden';
      this.container.width = (vis)? 250 : 0;
      this.container.height = (vis)? 100 : 0;
      break;
  }  
}

// end of context constructor

function jsrsGetContextID(){
  var contextObj;
  for (var i = 1; i <= jsrsContextPoolSize; i++){
    contextObj = jsrsContextPool[ 'jsrs' + i ];
    if ( !contextObj.busy ){
      contextObj.busy = true;      
      return contextObj.id;
    }
  }
  // if we got here, there are no existing free contexts
  if ( jsrsContextPoolSize <= jsrsContextMaxPool ){
    // create new context
    var contextID = "jsrs" + (jsrsContextPoolSize + 1);
    jsrsContextPool[ contextID ] = new jsrsContextObj( contextID );
    jsrsContextPoolSize++;
    return contextID;
  } else {
    alert( "jsrs Error:  context pool full" );
    return null;
  }
}

function jsrsExecute( rspage, callback, func, parms, visibility ){
  // call a server routine from client code
  //
  // rspage      - href to asp file
  // callback    - function to call on return
  //               or null if no return needed
  //               (passes returned string to callback)
  // func        - sub or function name  to call
  // parm        - string parameter to function
  //               or array of string parameters if more than one
  // visibility  - optional boolean to make container visible for debugging
 
  // get context
  var contextObj = jsrsContextPool[ jsrsGetContextID() ];
  contextObj.callback = callback;

  var vis = (visibility == null)? false : visibility;
  contextObj.setVisibility( vis );


  if ( jsrsPOST && ((jsrsBrowser == 'IE') || (jsrsBrowser == 'MOZ'))){
    contextObj.POST( rspage, func, parms );
  } else {
    contextObj.GET( rspage, func, parms );
  }  
 
  return contextObj.id;
}

function jsrsLoaded( contextID ){
  // get context object and invoke callback
  var contextObj = jsrsContextPool[ contextID ];
  if( contextObj.callback != null){
    contextObj.callback( jsrsUnescape( contextObj.getPayload() ), contextID );
  }
  // clean up and return context to pool
  contextObj.callback = null;
  contextObj.busy = false;
}

function jsrsError( contextID, str ){
  alert( unescape(str) );
  jsrsContextPool[ contextID ].busy = false
}

function jsrsEscapeQQ( thing ){
  return thing.replace(/'"'/g, '\\"');
}

function jsrsUnescape( str ){
  // payload has slashes escaped with whacks
  return str.replace( /\\\//g, "/" );
}

function jsrsBrowserSniff(){
  if (document.layers) return "NS";
  if (document.all) return "IE";
  if (document.getElementById) return "MOZ";
  return "OTHER";
}

/////////////////////////////////////////////////
//
// user functions

function jsrsArrayFromString( s, delim ){
  // rebuild an array returned from server as string
  // optional delimiter defaults to ~
  var d = (delim == null)? '~' : delim;
  return s.split(d);
}

function jsrsDebugInfo(){
  // use for debugging by attaching to f1 (works with IE)
  // with onHelp = "return jsrsDebugInfo();" in the body tag
  var doc = window.open().document;
  doc.open;
  doc.write( 'Pool Size: ' + jsrsContextPoolSize + '<br><font face="arial" size="2"><b>' );
  for( var i in jsrsContextPool ){
    var contextObj = jsrsContextPool[i];
    doc.write( '<hr>' + contextObj.id + ' : ' + (contextObj.busy ? 'busy' : 'available') + '<br>');
    doc.write( contextObj.container.document.location.pathname + '<br>');
    doc.write( contextObj.container.document.location.search + '<br>');
    doc.write( '<table border="1"><tr><td>' + contextObj.container.document.body.innerHTML + '</td></tr></table>' );
  }
  doc.write('</table>');
  doc.close();
  return false;
}




selectphp.js

// constants
var noValue = '-99'

// globals
var curOption = new Array();
var isLoaded = new Array();

function body_onLoad(){
  // initialize lists
  emptyList( 'lstCatagory' );
  emptyList( 'lstCapacity');
  emptyList( 'lstThread' );
  emptyList( 'lstStyle' );
  emptyList( 'lstMaterial');
  emptyList( 'lstColor' );
 
 
  jsrsExecute( 'select_rs.php', cbFillCatagory, 'CatagoryList' );
}

function lstCatagory_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    // don't allow novalue selection - revert to current
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    // init dependent lists
    emptyList( 'lstCapacity' );
    emptyList( 'lstThread');
      emptyList( 'lstStyle' );
        emptyList( 'lstMaterial');
        emptyList( 'lstColor' );
    window.status = 'Loading Capacity Selections...';
    jsrsExecute( 'select_rs.php', cbFillCapacity, 'CapacityList', val );
  }  
}

function lstCapacity_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    emptyList( 'lstThread');
      emptyList( 'lstStyle' );
        emptyList( 'lstMaterial');
        emptyList( 'lstColor' );
    window.status = 'Loading Thread Selections...';
    jsrsExecute( 'select_rs.php', cbFillThread, 'ThreadList', val );
  }  
}

function lstThread_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    emptyList( 'lstStyle' );
        emptyList( 'lstMaterial');
        emptyList( 'lstColor' );
    window.status = 'Loading Style Selections...';
    jsrsExecute( 'select_rs.php', cbFillStyle, 'StyleList', val );
  }  
}

function lstStyle_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    emptyList( 'lstMaterial');
        emptyList( 'lstColor' );
    window.status = 'Loading Material Selections...';
    jsrsExecute( 'select_rs.php', cbFillMaterial, 'MaterialList', val );
  }  
}

function lstMaterial_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    emptyList( 'lstColor' );
    window.status = 'Loading Color Selections...';
    jsrsExecute( 'select_rs.php', cbFillColor, 'ColorList', val );
  }  
}
function lstColor_onChange(){
  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    var msg = "You have selected: \n\n";
    msg += this.form.lstCatagory.options[this.form.lstCatagory.selectedIndex].text + "\n";
    msg += this.form.lstCapacity.options[this.form.lstCapacity.selectedIndex].text + "\n";
    msg += this.options[this.selectedIndex].text + "\n";
    alert (msg);
  }
}

function cbFillCatagory ( strCatagory ){
  window.status = '';
  fillList( 'lstCatagory',  strCatagory );
}

function cbFillCapacity ( strCapacity ){
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstCapacity',  strCapacity );
}

function cbFillThread( strThread ){
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstThread', strThread );
}

function cbFillStyle( strStyle ){
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstStyle', strStyle );
}

function cbFillMaterial( strMaterial ){
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstMaterial', strMaterial );
}

function cbFillColor( strColor ){
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstColor', strColor );
}

function fillList( listName, strOptions ){
  // fill any list with options
  emptyList( listName );
 
  // always insert selection prompt
  var lst = document.forms['QForm'][listName];
  lst.disabled = true;
  lst.options[0] = new Option('-- Select --', noValue);
 
  // options in form "value~displaytext|value~displaytext|..."
  var aOptionPairs = strOptions.split('|');
  for( var i = 0; i < aOptionPairs.length; i++ ){
    if (aOptionPairs[i].indexOf('~') != -1) {
      var aOptions = aOptionPairs[i].split('~');
      lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
    }  
  }
 
  // init to no value
  selectOption( listName, noValue );
  isLoaded[listName] = true;
  lst.disabled = false;
  lst.onchange = eval( listName + "_onChange" );
  // eval( "document.forms['QForm']['" + listName + "'].onchange=" + listName + "_onChange;" );
}

function emptyList( listName ){
  var lst = document.forms['QForm'][listName];
  lst.options.length = 0;
  lst.onchange = null;
  isLoaded[listName] = false;
  curOption[listName] = noValue;
}

function selectOption( listName, optionVal ){
  // set list selection to option based on value
  var lst = document.forms['QForm'][listName];
  for( var i = 0; i< lst.options.length; i++ ){
    if( lst.options[i].value == optionVal ){
      lst.selectedIndex = i;
      curOption[listName] = optionVal;
      return;
    }  
  }
}




select_rs.php

<?php

require("jsrsServer.php.inc");
jsrsDispatch( "CatagoryList CapacityList ThreadList StyleList MaterialList ColorList" );

function CatagoryList() {
  return serializeSql( "select prodlineID, prodline from tbCatagory order by prodlineID" );
}

function CapacityList( $prodlineID ) {
  return serializeSql( "select capacityID, capacity from tbCapacity where prodlineID=" . $prodlineID . " order by capacityID" );
}

function ThreadList( $capacityID ){
  return serializeSql( "select thread from tbProducts where capacityID=" . $capacityID . " order by thread" );
}

function StyleList( $thread ){
  return serializeSql( "select style from tbProducts where thread=" . $thread . " order by style" );
}

function MaterialList( $style ){
  return serializeSql( "select material from tbProducts where style=" . $style . " order by material" );
}

function ColorList( $material ){
  return serializeSql( "select color from tbProducts where material=" . $material . " order by color" );
}

function serializeSql( $sql ){
  $link=mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("$database");
 
  $result = mysql_query ($sql);
  $s = '';
  while ($row = mysql_fetch_row($result)) {
   $s .= join( $row, '~') . "|";
  }
 
  mysql_close($link);
  return $s;
}
   
?>


here is the mysql datadump:
# File name: C:\Documents and Settings\Kirstin Rowan\Desktop\testdump.sql
# Creation date: 04/12/2004
# Created by Excel to MySQL 2.1 [Demo]
# --------------------------------------------------
# More conversion tools at http://www.convert-in.com

#
# Table structure for table 'tbCapacity'
#

DROP TABLE IF EXISTS `tbCapacity`;
CREATE TABLE `tbCapacity` (
  `capacityID` DOUBLE,
  `prodlineID` VARCHAR(255),
  `capacity` VARCHAR(255)
);

#
# Dumping data for table 'tbCapacity'
#

LOCK TABLES `tbCapacity` WRITE;
INSERT INTO `tbCapacity` VALUES(2.500000000000000e-001, 'J', '1/4 oz');
INSERT INTO `tbCapacity` VALUES(5.000000000000000e-001, 'J', '1/2 oz');
INSERT INTO `tbCapacity` VALUES(8.750000000000000e-001, 'J', '7/8 oz');
INSERT INTO `tbCapacity` VALUES(1.000000000000000e+000, 'J', '1 oz');
INSERT INTO `tbCapacity` VALUES(1.500000000000000e+000, 'J', '1 1/2 oz');
UNLOCK TABLES;

#
# Table structure for table 'tbCatagory'
#

DROP TABLE IF EXISTS `tbCatagory`;
CREATE TABLE `tbCatagory` (
  `prodlineID` VARCHAR(255),
  `prodline` VARCHAR(255)
);

#
# Dumping data for table 'tbCatagory'
#

LOCK TABLES `tbCatagory` WRITE;
INSERT INTO `tbCatagory` VALUES('J', 'Jars');
INSERT INTO `tbCatagory` VALUES('C', 'Caps');
INSERT INTO `tbCatagory` VALUES('DD', 'Liners');
INSERT INTO `tbCatagory` VALUES('WC', 'Wax Containers');
INSERT INTO `tbCatagory` VALUES('JB', 'Jewelry Basket');
UNLOCK TABLES;

#
# Table structure for table 'tbColor'
#

DROP TABLE IF EXISTS `tbColor`;
CREATE TABLE `tbColor` (
  `colorID` VARCHAR(255),
  `color` VARCHAR(255)
);

#
# Dumping data for table 'tbColor'
#

LOCK TABLES `tbColor` WRITE;
INSERT INTO `tbColor` VALUES('CS', 'Clear');
INSERT INTO `tbColor` VALUES('NPP', 'Natural');
INSERT INTO `tbColor` VALUES('WPP', 'White');
INSERT INTO `tbColor` VALUES('BPP', 'Black');
INSERT INTO `tbColor` VALUES('MPP', 'Marble');
UNLOCK TABLES;

#
# Table structure for table 'tbMaterial'
#

DROP TABLE IF EXISTS `tbMaterial`;
CREATE TABLE `tbMaterial` (
  `materialID` VARCHAR(255),
  `material` VARCHAR(255)
);

#
# Dumping data for table 'tbMaterial'
#

LOCK TABLES `tbMaterial` WRITE;
INSERT INTO `tbMaterial` VALUES('PP', 'Polypropylene');
INSERT INTO `tbMaterial` VALUES('PS', 'Polystyrene');
INSERT INTO `tbMaterial` VALUES('PE', 'Polyethylene');
UNLOCK TABLES;

#
# Table structure for table 'tbProducts'
#

DROP TABLE IF EXISTS `tbProducts`;
CREATE TABLE `tbProducts` (
  `ItemID` VARCHAR(255),
  `prodlineID` VARCHAR(255),
  `capacityID` DOUBLE,
  `threadID` DOUBLE,
  `styleID` VARCHAR(255),
  `colorID` VARCHAR(255),
  `materialID` VARCHAR(255),
  `Ucost` DOUBLE,
  `U10M` DOUBLE,
  `10M25` DOUBLE,
  `25M50` DOUBLE,
  `O50` DOUBLE,
  `IPPB` DOUBLE,
  `Z2` DOUBLE,
  `Z3` DOUBLE,
  `stock` VARCHAR(255),
  `Volume` DOUBLE,
  `Overflow` DOUBLE,
  `Diameter` DOUBLE,
  `Height` DOUBLE,
  `Gram` DOUBLE,
  `PPB` DOUBLE,
  `Packing` VARCHAR(255),
  `Casewgt` DOUBLE,
  `Boxname` VARCHAR(255),
  `Boxmeas` VARCHAR(255),
  `CUFT` DOUBLE,
  `Fgtclass` DOUBLE,
  `Density` DOUBLE,
  `BPP` DOUBLE,
  `Picture` DOUBLE,
  `DWG` VARCHAR(255),
  `A` VARCHAR(255),
  `B` VARCHAR(255),
  `C` VARCHAR(255),
  `D` VARCHAR(255),
  `E` VARCHAR(255),
  `F38` VARCHAR(255),
  `F39` VARCHAR(255),
  `F40` VARCHAR(255),
  `x` VARCHAR(255),
  `F42` VARCHAR(255),
  `F43` VARCHAR(255),
  `F44` VARCHAR(255),
  `Fgt Charge` DOUBLE,
  `UPS table` DOUBLE,
  `diff` DOUBLE,
  `F48` VARCHAR(255),
  `F49` DOUBLE
);

#
# Dumping data for table 'tbProducts'
#

LOCK TABLES `tbProducts` WRITE;
INSERT INTO `tbProducts` VALUES('C070CD-PP', 'DD', NULL, 7.000000000000000e+001, 'K', 'NPP', 'PP', 9.000000000000000e-002, 9.000000000000000e+001, 8.370000000000000e+001, 7.740000000000001e+001, 7.110000000000001e+001, 7.157500000000000e+001, NULL, NULL, 'yes', NULL, NULL, NULL, NULL, NULL, 7.000000000000000e+002, 'Bulk', 7.000000000000000e+000, 'Jars', '25x15x13', 2.820000000000000e+000, 1.500000000000000e+002, 5.000000000000000e+000, 3.000000000000000e+001, NULL, "", "", "", "", "", "", "", "", "", "", "", "", "", 5.949999999999999e+000, 5.920000000000000e+000, 2.999999999999936e-002, "", NULL);
INSERT INTO `tbProducts` VALUES('C089CD-PP', 'DD', NULL, 8.900000000000000e+001, 'K', 'NPP', 'PP', 1.120000000000000e-001, 1.120000000000000e+002, 1.041600000000000e+002, 9.631999999999999e+001, 8.848000000000000e+001, 7.262500000000000e+001, NULL, NULL, 'yes', NULL, NULL, NULL, NULL, NULL, 5.500000000000000e+002, 'Bulk', 9.000000000000000e+000, 'Jars', '25x15x13', 2.820000000000000e+000, 1.250000000000000e+002, 6.000000000000000e+000, 3.000000000000000e+001, NULL, "", "", "", "", "", "", "", "", "", "", "", "", "", 6.650000000000000e+000, 5.920000000000000e+000, 7.300000000000004e-001, "", NULL);
INSERT INTO `tbProducts` VALUES('C033CD-PE', 'DD', NULL, 3.300000000000000e+001, 'K', 'NPP', 'PE', 1.752000000000000e-002, 1.752000000000000e+001, 1.629360000000000e+001, 1.506720000000000e+001, 1.384080000000000e+001, 1.056150000000000e+002, NULL, NULL, 'yes', NULL, NULL, NULL, NULL, NULL, 4.500000000000000e+003, 'Bulk', 9.000000000000000e+000, '89', '24x16x26', 5.750000000000000e+000, 1.500000000000000e+002, 3.400000000000000e+000, 1.500000000000000e+001, NULL, "", "", "", "", "", "", "", "", "", "", "", "", "", 6.650000000000000e+000, 5.920000000000000e+000, 7.300000000000004e-001, "", NULL);
INSERT INTO `tbProducts` VALUES('A1204000CSC', 'J', 4.000000000000000e+001, 1.200000000000000e+002, 'A', 'CS', 'PS', 6.750000000000000e-001, 6.750000000000000e+002, 6.345000000000000e+002, 5.940000000000000e+002, 5.535000000000000e+002, 3.250000000000000e+001, 9.500000000000001e-001, 8.500000000000000e-001, 'yes', 1.166000000000000e+003, 1.270000000000000e+003, 4.375000000000000e+000, 5.062500000000000e+000, NULL, 3.000000000000000e+001, 'Layer', 1.000000000000000e+001, 'Jars', '25x15x13', 2.820000000000000e+000, 8.500000000000000e+001, 1.240000000000000e+001, 3.000000000000000e+001, NULL, "", "", "", "", "", "", "", "", "", "", "", "", "", 7.000000000000000e+000, 5.920000000000000e+000, 1.080000000000000e+000, "", NULL);
INSERT INTO `tbProducts` VALUES('A0892000CSC', 'J', 2.000000000000000e+001, 8.900000000000000e+001, 'A', 'CS', 'PS', 4.220000000000000e-001, 4.220000000000000e+002, 3.966800000000000e+002, 3.713600000000000e+002, 3.460400000000000e+002, 3.710700000000000e+001, 9.500000000000001e-001, 8.500000000000000e-001, 'yes', 6.000000000000000e+002, 6.700000000000000e+002, 3.125000000000000e+000, 5.000000000000000e+000, NULL, 5.600000000000000e+001, 'Layer', 1.100000000000000e+001, 'Caps', '25x15x13', 2.820000000000000e+000, 1.000000000000000e+002, 9.200000000000001e+000, 3.000000000000000e+001, NULL, "", "", "", "", "", "", "", "", "", "", "", "", "", 7.350000000000000e+000, 7.630000000000000e+000, -2.800000000000003e-001, "", NULL);
UNLOCK TABLES;
ALTER TABLE `tbProducts` CHANGE `capacityID` `capacityID` INTEGER;
ALTER TABLE `tbProducts` CHANGE `threadID` `threadID` INTEGER;
ALTER TABLE `tbProducts` CHANGE `Volume` `Volume` INTEGER;
ALTER TABLE `tbProducts` CHANGE `Overflow` `Overflow` INTEGER;
ALTER TABLE `tbProducts` CHANGE `Gram` `Gram` INTEGER;
ALTER TABLE `tbProducts` CHANGE `PPB` `PPB` INTEGER;
ALTER TABLE `tbProducts` CHANGE `Casewgt` `Casewgt` INTEGER;
ALTER TABLE `tbProducts` CHANGE `Fgtclass` `Fgtclass` INTEGER;
ALTER TABLE `tbProducts` CHANGE `BPP` `BPP` INTEGER;
ALTER TABLE `tbProducts` CHANGE `Picture` `Picture` INTEGER;
ALTER TABLE `tbProducts` CHANGE `F49` `F49` INTEGER;

#
# Table structure for table 'tbStyle'
#

DROP TABLE IF EXISTS `tbStyle`;
CREATE TABLE `tbStyle` (
  `styleID` VARCHAR(255),
  `style` VARCHAR(255)
);

#
# Dumping data for table 'tbStyle'
#

LOCK TABLES `tbStyle` WRITE;
INSERT INTO `tbStyle` VALUES('A', 'Regular Wall');
INSERT INTO `tbStyle` VALUES('B', 'Thick Wall');
INSERT INTO `tbStyle` VALUES('C', 'Frostique Thick Wall ');
INSERT INTO `tbStyle` VALUES('D', 'Tapered Thick Wall');
INSERT INTO `tbStyle` VALUES('E', 'Lined Smooth');
UNLOCK TABLES;

#
# Table structure for table 'tbThread'
#

DROP TABLE IF EXISTS `tbThread`;
CREATE TABLE `tbThread` (
  `threadID` DOUBLE,
  `thread` VARCHAR(255)
);

#
# Dumping data for table 'tbThread'
#

LOCK TABLES `tbThread` WRITE;
INSERT INTO `tbThread` VALUES(3.300000000000000e+001, '33 mm');
INSERT INTO `tbThread` VALUES(3.800000000000000e+001, '38 mm');
INSERT INTO `tbThread` VALUES(4.300000000000000e+001, '43 mm');
INSERT INTO `tbThread` VALUES(4.800000000000000e+001, '48 mm');
INSERT INTO `tbThread` VALUES(5.300000000000000e+001, '53 mm');
UNLOCK TABLES;
ALTER TABLE `tbThread` CHANGE `threadID` `threadID` INTEGER;


0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
nope sorry ive not heard of that JS thing.
ok after having a look around i can't seem to find that code, but can try and help you still.

first here is a function that will add a new option to a select box
// adds a new option to a select input
function addSelectOption(form1,selectobj, val, atr) {
    var index = selectobj.options.length;
    form1.elements[selectobj.name].options[index]= new Option(atr,val);
}

you pass in the form, the select, the value of the option and the text for the option.

then what i have is a function for each select box that is called when onChange happens.
this function will check what value was selected then it populates another select box with the appropriate values.

function changeCapacityBox(control, form1) {
    var productline = control.value;

   form1.capacity.options.length = 0; // remove all options from capacity box

   if (country == "DD")
   {
       addSelectOption(form1,form1.capacity, "1/4 oz", "1/4 oz");
       // and so on
   }
   else if (productline == "J")
   {
       addSelectOption(form1,form1.capacity "1 oz", "1oz");
       // and so on
   }
   // put more else conditions here if needed
}

the hard bit of course will be to work out the queries and then use php to generate the javascript code, but when you finally manage it, it will be an impressive bit of coding ;)

if i had more time available i would try and create a little demo for you.

let me know how things go








0
 

Author Comment

by:Kristina5
Comment Utility
just quickly, where do these go on the page?

in the body, the header?
0
 

Author Comment

by:Kristina5
Comment Utility
also what about the arrays? do I still need to use them if I want the options to fill dynamically? and if so where do they go on the page? in the header or  body?
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
well since you are generating the javascript it should go in between the <head> tag.

and for each select box you would add the appropriate onChange function

<select name="products" onChange="changeCapacityBox(this,this.form)">

etc
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
which arrays are they? the code i showed u before will populate the select boxes dynamically. so you wont need seperate arrays
0
 

Author Comment

by:Kristina5
Comment Utility
oh ok great
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
hi, are you still there?
i have written some code for you, it should help you understand a bit i hope.

<?php

// connect to db
$connect = mysql_pconnect("localhost","root","");
mysql_select_db("test");

// get results for 1st select box
$query1 = "select make_id,make from car_makes";

$result = mysql_query($query1);
?>
<html>
<head>
      <title>test</title>
<?php
      print "<script language=\"JavaScript\">";
      print "function changeModel(control, form1) {\n";
      print "var make = control.value;\n";
      print "form1.models.options.length = 0;\n";
      while ($row = mysql_fetch_array($result)) {
            // get models for each make
            $makeId = $row["make_id"];
            $make = $row["make"];
            print "if (make == \"$make\") { \n";
            $query2 = "select model_id,model from car_models where make_id=$makeId";
            $result2 = mysql_query($query2);
            while ($row2 = mysql_fetch_array($result2)) {
                  // write out js code for each row
                  $model = $row2["model"];
                  print "addSelectOption(form1,form1.models, \"$model\", \"$model\");\n";
            }

            print "}\n"; // end if
      }
      print "}\n"; // end function
      print "</script>\n";
?>
      <script language="JavaScript">
            function addSelectOption(form1,selectobj, val, atr) {
                  var index = selectobj.options.length;
                  form1.elements[selectobj.name].options[index]= new Option(atr,val);
            }
      </script>
</head>
<body>
<form name="mainForm">
Make:<select name="makes" onChange="changeModel(this,this.form);">
<option value="">Select a make</option>
<?php
      $result = mysql_query($query1);
      while ($row = mysql_fetch_array($result))
      {
?>
            <option value="<?=$row["make"]?>"><?=$row["make"]?></option>
<?php
      }
?>
</select>
<br />
Models:
<select name="models">
      <option value="">Please select make first</option>
</select>
</form>
</body>
</html>

// DATABASE USED
#
# Table structure for table `car_models`
#

CREATE TABLE car_models (
  model_id int(11) NOT NULL default '0',
  make_id int(11) NOT NULL default '0',
  model varchar(80) NOT NULL default ''
) TYPE=MyISAM;

#
# Dumping data for table `car_models`
#

INSERT INTO car_models VALUES (1, 1, '316i');
INSERT INTO car_models VALUES (2, 1, '320i');
INSERT INTO car_models VALUES (3, 1, 'z3');
INSERT INTO car_models VALUES (4, 3, 'corsa');
INSERT INTO car_models VALUES (5, 3, 'vectra');
INSERT INTO car_models VALUES (6, 3, 'astra');
INSERT INTO car_models VALUES (7, 2, 'focus');
INSERT INTO car_models VALUES (8, 2, 'fiesta');
INSERT INTO car_models VALUES (9, 2, 'mondeo');
0
 

Author Comment

by:Kristina5
Comment Utility
yes, still struggling! :)
thanks!
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
so what is all this for? are you working for a company?
0
 

Author Comment

by:Kristina5
Comment Utility
yes, my parents have a plastic jar company and I am helping them build their website. I am a web deisgner, not a programer though so I usually don't get involved to much in the back end of things
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
im sorta the opposite, not a designer more a programmer.
do you work full time as a web designer?
0
 

Author Comment

by:Kristina5
Comment Utility
no, not normally. I used to work in client relations for a hedge fund. But I moved to France last year and so told my dad I would help him out. It keeps me busy :)
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
ah so your in france right now? where r u from originally? im from scotland, up in the north east at the moment
0
 

Author Comment

by:Kristina5
Comment Utility
how crazy... it's a small world... never would have guessed... you don't have an accent ;)

I am from the united states originally but I have been in France since August.
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
well thats a lot closer than the states, i have family in france, near Caen in Normandy.
so did that last bit of code help you at all?
did you manage to get it running
0
 

Author Comment

by:Kristina5
Comment Utility
cool... I am a bit south of that in Nantes... where are you? Paris? I got side tracked and haven't actually tried it yet but I will try it now and get back to you in a few.
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
sorry maybe i got you confused there, when i said north east i meant of scotland not france :)
im not sure i could survive in france, my french is v poor :'(
0
 

Author Comment

by:Kristina5
Comment Utility
mine too :)

gotcha! Love scotland. where? I spent a week in southern scotland a few years ago.
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
in aberdeen if you know it.
0
 

Author Comment

by:Kristina5
Comment Utility
hey does that code you gave me work for you as is? I uploaded both tables to my server and I am still running into the same problems. I didn't do anything to the code yet. I was just wondering if it was working for you?
0
 

Author Comment

by:Kristina5
Comment Utility
forget it... made a few changes and now it is working. I am going to try and duplicate for my search. thanks again!
0
 

Author Comment

by:Kristina5
Comment Utility
FINALLY!!! It was my tables that were the problem all along. They were set to NULL and weren't working with your code or anything else that I tried!!! i just finally figured it out thank you. So annoying!!! Anyway I have the two working and am going to try and get the other 4 working as well. I will keep you posted thank you again!!!!
0
 

Author Comment

by:Kristina5
Comment Utility
sorry jumped the gun... the first menu is working and pulling from the database and the second was pulling from the database but was pulling all of rows each time - no matter what product line was selected. there was only one product line in the database so I updated the database and now there are different productIDs in the database and now the second menu isn't working at all...all I did was change the variables I don't know why it's not working. Did I change something I shouldn't have?

<?php

// connect to db
$db=mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("$database");

// get results for 1st select box
$query1 = "select prodlineID, prodline from tbCatagory";

$result = mysql_query($query1, $db) or die(mysql_error());
?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodlineID == \"$prodlineID\") { \n";
          $query2 = "select capacityID, capacity from tbCapacity where prodlineID=$prodline_ID";
          $result2 = mysql_query($query2, $db);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
     <script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
     </script>
</head>
<body>
<form name="mainForm">
  Category:
<select name="catagoryMenu" onChange="changeCapacity(this,this.form);">
<option value="">Select a make</option>
<?php
     $result = mysql_query($query1) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodlineID"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
<br />
Capacity:
<select name="capacityMenu">
     <option value="">Please select make first</option>
</select>
</form>
</body>
</html>
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
hi, i will check this in the afternoon, dont give up hope! :)
0
 

Author Comment

by:Kristina5
Comment Utility
thanks! :)

I just checked it again... this code was def working with your make/model scenerio before I changed the variables, so check this one. Thanks again.
<?php

// connect to db
$db=mysql_connect ("localhost", "krdesig_krowan01", "skimore") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("krdesig_Products");
      
// get results for 1st select box
$query1 = "select prodlineID,prodline from tbCatagory";

$result = mysql_query($query1, $db) or die(mysql_error());
?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodline == \"$prodline\") { \n";
          $query2 = "select capacityID,capacity from tbCapacity where prodlineID=$prodline_ID";
          $result2 = mysql_query($query2, $db) or die(mysql_error());
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
     <script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
     </script>
</head>
<body>
<form name="mainForm">
Make:<select name="catagoryMenu" onChange="changeCapacity(this,this.form);">
<option value="">Select Product Type</option>
<?php
     $result = mysql_query($query1, $db) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
<br />
Capacity:
<select name="capacityMenu">
     <option value="">Please select Product Type first</option>
</select>
</form>
</body>
</html>
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
hi, what is the error, as i can't test any code here im not at my machine.
0
 

Author Comment

by:Kristina5
Comment Utility
there is no error, you can see the results here:

www.krdesign4u.com/workingmenukr.php

as you can see the first menu is pulling info from the database however there is something wrong with the second menu. For some reason it is not pulling info from the database.
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
ok the second query is not workign can you test it out

select capacityID,capacity from tbCapacity where prodlineID=$prodline_ID

is prodlineID an int? or is it varchar? if so you will need quotes like this prodlineID='$prodline_ID'
0
 

Author Comment

by:Kristina5
Comment Utility
ah maybe that is it... prodlineID is an int but capacityID and capacity are varchar
0
 

Author Comment

by:Kristina5
Comment Utility
I have tried it 100 different ways and nothing seems to work. If you can look at it when you get home I would really appreciate it! Thank you!
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
in the database you showed me prodlineID was a varchar e.g. J so if thats still the case
then you will need single quotes around $prodlineID
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Kristina5
Comment Utility
Thank you! I actually changed my database based on your database, so it is an int but somehow when I uploaded the new tables all of the prodlineIDs reset to 0? I am not sure why, but obviously the IDs weren't matching up. So that was the problem. It is working now! FINALLY!

i am going to try and add the additional dropdown menus. Fingers crossed! :)

thank you
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
woohoo! :D
0
 

Author Comment

by:Kristina5
Comment Utility
ok... tried to create the 6 step menu and this is what I came up with. It still isn't working for me (of course ;)... the last three menus aren't printing and the thread menu is having problems pulling info from that database. I'll continue to try and find the problem, but just thought I would put it up here incase you were able to see the problem right away. Thanks.

<?php

// connect to db
      
// get results for 1st select box
$query1 = "select prodlineID,prodline from tbCatagory";
$result = mysql_query($query1, $db) or die(mysql_error());

?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodline == \"$prodline\") { \n";
     
              $query2 = "SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
          $result2 = mysql_query($query2, $db) or die(mysql_error());
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.threadMenu.options.length = 0;\n";
     while ($row2 = mysql_fetch_array($result2)) {
          // get models for each make
          $capacity_ID = $row2["capacityID"];
          $capacity = $row2["capacity"];
          print "if (capacity == \"$capacity\") { \n";
     
              $query3 = "SELECT 'threadID', 'thread' FROM 'tbProducts' WHERE capacityID=$capacity_ID";
          $result3 = mysql_query($query3, $db) or die(mysql_error());
          while ($row3 = mysql_fetch_array($result3)) {
               // write out js code for each row
               $thread = $row3["thread"];
               print "addSelectOption(form1,form1.threadMenu, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.styleMenu.options.length = 0;\n";
     while ($row3 = mysql_fetch_array($result3)) {
          // get models for each make
          $thread_ID = $row3["threadID"];
          $thread = $row3["thread"];
          print "if (thread == \"$thread\") { \n";
     
              $query4 = "SELECT styleID, style FROM tbProducts WHERE threadID=$thread_ID AND prodlineID=$prodline_ID";
          $result4 = mysql_query($query4, $db) or die(mysql_error());
          while ($row4 = mysql_fetch_array($result4)) {
               // write out js code for each row
               $style = $row4["style"];
               print "addSelectOption(form1,form1.styleMenu, \"$style\", \"$stlye\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.materialMenu.options.length = 0;\n";
     while ($row4 = mysql_fetch_array($result4)) {
          // get models for each make
          $style_ID = $row4["styleID"];
          $style= $row4["style"];
          print "if (style == \"$style\") { \n";
     
              $query5 = "SELECT materialID, material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
          $result5 = mysql_query($query5, $db) or die(mysql_error());
          while ($row5 = mysql_fetch_array($result5)) {
               // write out js code for each row
               $material = $row5["material"];
               print "addSelectOption(form1,form1.materialMenu, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeColor(control, form1) {\n";
     print "var color = control.value;\n";
     print "form1.colorMenu.options.length = 0;\n";
     while ($row5 = mysql_fetch_array($result5)) {
          // get models for each make
          $material_ID = $row5["materialID"];
          $material= $row5["material"];
          print "if (material == \"$material\") { \n";
     
              $query6 = "SELECT colorID, color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
          $result6 = mysql_query($query6, $db) or die(mysql_error());
          while ($row6 = mysql_fetch_array($result6)) {
               // write out js code for each row
               $color = $row6["color"];
               print "addSelectOption(form1,form1.colorMenu, \"$color\", \"$color\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
</script>
</head>
<body><form name="mainForm"><table><tr>
<td width="67">
  Catagory: </td><td width="187">
  <select name="catagoryMenu" onChange="changeCapacity(this,this.form);">
<option value="">Select Product Type</option>
<?php
     $result = mysql_query($query1, $db) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Capacity:</td><td>
<select name="capacityMenu" onChange="changeThread(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result2 = mysql_query($query2, $db) or die(mysql_error());
     while ($row2 = mysql_fetch_array($result2))
     {
?>
              <option value="">-- select a capacity --</option>
          <option value="<?=$row2["capacity"]?>"><?=$row2["capacity"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Thread:</td><td>
<select name="threadMenu" onChange="changeStyle(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result3 = mysql_query($query3, $db) or die(mysql_error());
     while ($row3 = mysql_fetch_array($result3))
     {
?>
          <option value="<?=$row3["thread"]?>"><?=$row3["thread"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Style:</td><td>
<select name="styleMenu" onChange="changeMaterial(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result4 = mysql_query($query4, $db) or die(mysql_error());
     while ($row4 = mysql_fetch_array($result4))
     {
?>
          <option value="<?=$row4["style"]?>"><?=$row4["style"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Material:</td><td>
<select name="materialMenu" onChange="changeColor(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result5 = mysql_query($query5, $db) or die(mysql_error());
     while ($row5 = mysql_fetch_array($result5))
     {
?>
          <option value="<?=$row5["material"]?>"><?=$row5["material"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Color:</td><td>
<select name="colorMenu">
     <option value="">Please select Product Type first</option>
</select>
</td></tr></table></form>
</body>
</html>


you can see what this looks like right now at: http://www.krdesign4u.com/workingmenukrtest.php


#
#
# Table structure for table `tbCapacity`
#

CREATE TABLE `tbCapacity` (
  `capacityID` int(11) NOT NULL default '0',
  `capacity` varchar(80) NOT NULL default '',
  `prodlineID` int(11) NOT NULL default '0'
) TYPE=MyISAM;

#
# Dumping data for table `tbCapacity`
#

INSERT INTO `tbCapacity` VALUES (1, '1/4 oz', 1);
INSERT INTO `tbCapacity` VALUES (2, '1/2 oz', 1);
INSERT INTO `tbCapacity` VALUES (3, '7/8 oz', 1);
INSERT INTO `tbCapacity` VALUES (4, '1 oz', 1);
INSERT INTO `tbCapacity` VALUES (5, '1 1/2 oz', 1);


#
# Table structure for table `tbProducts`
#

CREATE TABLE `tbProducts` (
  `Item` varchar(80) NOT NULL default '',
  `Desc` varchar(80) NOT NULL default '',
  `prodlineID` int(11) NOT NULL default '0',
  `prodline` varchar(80) NOT NULL default '',
  `capacityID` int(11) NOT NULL default '0',
  `capacity` varchar(80) NOT NULL default '',
  `threadID` int(11) NOT NULL default '0',
  `thread` varchar(80) NOT NULL default '',
  `styleID` int(11) NOT NULL default '0',
  `style` varchar(80) NOT NULL default '',
  `materialID` int(11) NOT NULL default '0',
  `material` varchar(80) NOT NULL default '',
  `colorID` int(11) NOT NULL default '0',
  `color` varchar(80) NOT NULL default '',
  `Ucost` varchar(80) NOT NULL default '',
  `U10M` double NOT NULL default '0',
  `10M25` double NOT NULL default '0',
  `25M50` double NOT NULL default '0',
  `O50` double NOT NULL default '0',
  `IPPB` double NOT NULL default '0',
  `Z2` double NOT NULL default '0',
  `Z3` double NOT NULL default '0',
  `stock` varchar(80) NOT NULL default '',
  `Volume` double NOT NULL default '0',
  `Overflow` double NOT NULL default '0',
  `Diameter` int(11) NOT NULL default '0',
  `Height` double NOT NULL default '0',
  `PPB` int(11) NOT NULL default '0',
  `Packing` varchar(255) NOT NULL default '',
  `Casewgt` int(11) NOT NULL default '0',
  `Boxname` varchar(255) NOT NULL default '',
  `Boxmeas` varchar(255) NOT NULL default '',
  `CUFT` double NOT NULL default '0',
  `Fgtclass` int(11) NOT NULL default '0',
  `Density` double NOT NULL default '0',
  `BPP` int(11) NOT NULL default '0',
  `Picture` varchar(255) NOT NULL default '',
  `DWG` varchar(255) NOT NULL default '',
  `A` varchar(255) NOT NULL default '',
  `B` varchar(255) NOT NULL default '',
  `C` varchar(255) NOT NULL default '',
  `D` varchar(255) NOT NULL default '',
  `E` varchar(255) NOT NULL default '',
  `F44` varchar(255) NOT NULL default '',
  `F45` varchar(255) NOT NULL default '',
  `F46` varchar(255) NOT NULL default '',
  `x` varchar(255) NOT NULL default '',
  `F48` varchar(255) NOT NULL default '',
  `F49` varchar(255) NOT NULL default '',
  `F50` varchar(255) NOT NULL default '',
  `Fgt Charge` double NOT NULL default '0',
  `UPS table` double NOT NULL default '0',
  `diff` double NOT NULL default '0',
  `F54` varchar(255) NOT NULL default '',
  `F55` int(11) NOT NULL default '0',
  `F56` varchar(255) NOT NULL default '',
  `F57` varchar(255) NOT NULL default '',
  `F58` varchar(255) NOT NULL default '',
  `F59` varchar(255) NOT NULL default ''
) TYPE=MyISAM;

#
# Dumping data for table `tbProducts`
#

INSERT INTO `tbProducts` VALUES ('A0330025CSC', '1/4oz 33mm Clear Styrene Jar', 1, 'Jar', 1, '1/4oz', 1, '33mm', 1, 'Regular Wall', 3, 'Styrene', 1, 'Clear', '0.0609000', '60.9', '57.246', '53.592', '49.938', '212.3597', '0.95', '0.85', 'yes', '10', '15', 1, '1', 2783, 'Layer', 35, '89', '24x16x26', '5.75', 150, '6.08695652173913', 15, 'A0330025CSC.jpg', 'A0330025CSC_spec.jpg', '', '', '', '', '', '', '', '', '', '', '', '', '15.75', '5.92', '9.83', '', 0, '', '', '', '');
INSERT INTO `tbProducts` VALUES ('A0330025PPN', '1/4oz 33mm Natural Polypro Jar', 1, 'Jar', 1, '1/4oz', 1, '33mm', 1, 'Regular Wall', 2, 'Polypro', 3, 'Natural', '0.0556500', '55.65', '52.311', '48.972', '45.633', '170.975', '0.95', '0.85', 'yes', '9.5', '14.25', 1, '1', 2500, 'Bulk', 26, 'Caps', '25x15x13', '2.82', 125, '7.4', 30, 'A0330025PPN.jpg', 'A0330025PPN_spec.jpg', '', '', '', '', '', '', '', '', '', '', '', '', '12.6', '5.92', '6.68', '', 0, '', '', '', '');
INSERT INTO `tbProducts` VALUES ('A0330025PPW', '1/4oz 33mm White Polypro Jar', 1, 'Jar', 1, '1/4oz', 1, '33mm', 1, 'Regular Wall', 2, 'Polypro', 2, 'White', '0.0556500', '55.65', '52.311', '48.972', '45.633', '170.975', '0.95', '0.85', 'yes', '9.5', '14.25', 1, '1', 2500, 'Bulk', 26, 'Caps', '25x15x13', '2.82', 125, '6', 30, 'A0330025PPW.jpg', 'A0330025PPW_spec.jpg', '', '', '', '', '', '', '', '', '', '', '', '', '12.6', '5.92', '6.68', '', 0, '', '', '', '');
INSERT INTO `tbProducts` VALUES ('A0330050CSC', '1/2oz 33mm Clear Styrene Jar', 1, 'Jar', 2, '1/2oz', 1, '33mm', 1, 'Regular Wall', 3, 'Styrene', 1, 'Clear', '0.0693000', '69.3', '65.142', '60.984', '56.826', '180.6882', '0.95', '0.85', 'yes', '15', '19', 1, '1.4375', 2024, 'Layer', 33, 'Caps', '25x15x13', '2.82', 125, '7.4', 30, 'A0330050CSC.jpg', 'A0330050CSC_spec.jpg', '', '', '', '', '', '', '', '', '', '', '', '', '15.05', '5.92', '9.13', '', 0, '', '', '', '');
INSERT INTO `tbProducts` VALUES ('A0330050PPN', '1/2oz 33mm Natural Polypro Jar', 1, 'Jar', 2, '1/2oz', 1, '33mm', 1, 'Regular Wall', 2, 'Polypro', 3, 'Natural', '0.0640500', '64.05', '60.207', '56.364', '52.521', '145.915', '0.95', '0.85', 'yes', '14.25', '18.05', 1, '1.4375', 1800, 'Bulk', 25, 'Caps', '25x15x13', '2.82', 100, '8.8', 30, 'A0330050PPN.jpg', 'A0330050PPN_spec.jpg', '', '', '', '', '', '', '', '', '', '', '', '', '12.25', '7.63', '4.62', '', 0, '', '', '', '');
   
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
ok for the changethread function

you will have to requery the db

$result2 = mysql_query($query2);

because you already looped throguh $result2 so its now at the end
thats why nothing is getting output for the javascript function

now since you are using queries in more than one place you best define them all
at the top outside any functions. otherwise you wont have access to them between functions.
and its easier to see too :)
0
 

Author Comment

by:Kristina5
Comment Utility
Good Morning!

That's what I figured, so I tried running all of the queries in the begining last night but I kept coming up with this error. I didn't know what it was refering to because to me line 1 looks fine?! It is just the opening php tag? I also tried dupluicating the queries in the header and I still get the same message.

<--error -->

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

<--code -->

<?php
// connect to db
$db=mysql_connect ("localhost", "krdesig_krowan01", "skimore") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("krdesig_Products");
      
// get results for 1st select box
$query1 = "select prodlineID,prodline from tbCatagory";
$result = mysql_query($query1, $db) or die(mysql_error());

$query2 = "SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
$result2 = mysql_query($query2, $db) or die(mysql_error());

$query3 = "SELECT threadID, thread FROM tbProducts WHERE capacityID=$capacity_ID";
$result3 = mysql_query($query3, $db) or die(mysql_error());

$query4 = "SELECT styleID, style FROM tbProducts WHERE threadID=$thread_ID AND prodlineID=$prodline_ID";
$result4 = mysql_query($query4, $db) or die(mysql_error());

$query5 = "SELECT materialID, material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
$result5 = mysql_query($query5, $db) or die(mysql_error());

$query6 = "SELECT colorID, color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
$result6 = mysql_query($query6, $db) or die(mysql_error());

?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodline == \"$prodline\") { \n";
     
              while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.threadMenu.options.length = 0;\n";
     while ($row2 = mysql_fetch_array($result2)) {
          // get models for each make
          $capacity_ID = $row2["capacityID"];
          print "if (capacity == \"$capacity\") { \n";
     
          while ($row3 = mysql_fetch_array($result3)) {
               // write out js code for each row
               $thread = $row3["thread"];
               print "addSelectOption(form1,form1.threadMenu, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.styleMenu.options.length = 0;\n";
     while ($row3 = mysql_fetch_array($result3)) {
          // get models for each make
          $thread_ID = $row3["threadID"];
          $thread = $row3["thread"];
          print "if (thread == \"$thread\") { \n";
     
          while ($row4 = mysql_fetch_array($result4)) {
               // write out js code for each row
               $style = $row4["style"];
               print "addSelectOption(form1,form1.styleMenu, \"$style\", \"$stlye\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.materialMenu.options.length = 0;\n";
     while ($row4 = mysql_fetch_array($result4)) {
          // get models for each make
          $style_ID = $row4["styleID"];
          $style= $row4["style"];
          print "if (style == \"$style\") { \n";
     
          while ($row5 = mysql_fetch_array($result5)) {
               // write out js code for each row
               $material = $row5["material"];
               print "addSelectOption(form1,form1.materialMenu, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeColor(control, form1) {\n";
     print "var color = control.value;\n";
     print "form1.colorMenu.options.length = 0;\n";
     while ($row5 = mysql_fetch_array($result5)) {
          // get models for each make
          $material_ID = $row5["materialID"];
          $material= $row5["material"];
          print "if (material == \"$material\") { \n";
     
          while ($row6 = mysql_fetch_array($result6)) {
               // write out js code for each row
               $color = $row6["color"];
               print "addSelectOption(form1,form1.colorMenu, \"$color\", \"$color\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
</script>
</head>
<body><form name="mainForm"><table><tr>
<td width="67">
  Catagory: </td><td width="187">
  <select name="catagoryMenu" onChange="changeCapacity(this,this.form);">
<option value="">Select Product Type</option>
<?php
     $result = mysql_query($query1, $db) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Capacity:</td><td>
<select name="capacityMenu" onChange="changeThread(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result2 = mysql_query($query2, $db) or die(mysql_error());
     while ($row2 = mysql_fetch_array($result2))
     {
?>
              <option value="">-- select a capacity --</option>
          <option value="<?=$row2["capacity"]?>"><?=$row2["capacity"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Thread:</td><td>
<select name="threadMenu" onChange="changeStyle(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result3 = mysql_query($query3, $db) or die(mysql_error());
     while ($row3 = mysql_fetch_array($result3))
     {
?>
          <option value="<?=$row3["thread"]?>"><?=$row3["thread"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Style:</td><td>
<select name="styleMenu" onChange="changeMaterial(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result4 = mysql_query($query4, $db) or die(mysql_error());
     while ($row4 = mysql_fetch_array($result4))
     {
?>
          <option value="<?=$row4["style"]?>"><?=$row4["style"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Material:</td><td>
<select name="materialMenu" onChange="changeColor(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result5 = mysql_query($query5, $db) or die(mysql_error());
     while ($row5 = mysql_fetch_array($result5))
     {
?>
          <option value="<?=$row5["material"]?>"><?=$row5["material"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Color:</td><td>
<select name="colorMenu">
     <option value="">Please select Product Type first</option>
</select>
</td></tr></table></form>
</body>
</html>
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
one of your queries isn't working
its not referering to the line number on php

what to do is add a number to the die function where you print the mysql_error that way you will know
which query is causing the problem

e.g.
$result = mysql_query($query1, $db) or die("query1" . mysql_error());
0
 

Author Comment

by:Kristina5
Comment Utility
Ok, great changed it, the error message I am getting now is:

query2You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

but I am not sure why because my second query was working fine. It was the third query that was a problem?

<?php

// connect to db

      
// get results for 1st select box
$query1 = "select prodlineID,prodline from tbCatagory";
$result = mysql_query($query1, $db) or die("query1" . mysql_error());

$query2 = "SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
$result2 = mysql_query($query2, $db) or die("query2" . mysql_error());

$query3 = "SELECT threadID, thread FROM tbProducts WHERE prodlineID=$prodline_ID AND capacityID=$capacity_ID";
$result3 = mysql_query($query3, $db) or die("query3" . mysql_error());

$query4 = "SELECT styleID, style FROM tbProducts WHERE prodlineID=$prodline_ID AND capacityID=$capacity_ID AND threadID=$thread_ID";
$result4 = mysql_query($query4, $db) or die("query4" . mysql_error());

$query5 = "SELECT materialID, material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
$result5 = mysql_query($query5, $db) or die("query5" . mysql_error());

$query6 = "SELECT colorID, color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
$result6 = mysql_query($query6, $db) or die("query6" . mysql_error());


?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodline == \"$prodline\") { \n";
     
              $query2 = "SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
          $result2 = mysql_query($query2, $db) or die(mysql_error());
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.threadMenu.options.length = 0;\n";
       $result2 = mysql_query($query2);
     while ($row2 = mysql_fetch_array($result2)) {
          // get models for each make
          $capacity_ID = $row2["capacityID"];
          print "if (capacity == \"$capacity\") { \n";
     
              $query3 = "SELECT 'threadID', 'thread' FROM 'tbProducts' WHERE capacityID=$capacity_ID";
          $result3 = mysql_query($query3, $db) or die(mysql_error());
          while ($row3 = mysql_fetch_array($result3)) {
               // write out js code for each row
               $thread = $row3["thread"];
               print "addSelectOption(form1,form1.threadMenu, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.styleMenu.options.length = 0;\n";
       $result3 = mysql_query($query3);
     while ($row3 = mysql_fetch_array($result3)) {
          // get models for each make
          $thread_ID = $row3["threadID"];
          $thread = $row3["thread"];
          print "if (thread == \"$thread\") { \n";
     
              $query4 = "SELECT styleID, style FROM tbProducts WHERE threadID=$thread_ID AND prodlineID=$prodline_ID";
          $result4 = mysql_query($query4, $db) or die(mysql_error());
          while ($row4 = mysql_fetch_array($result4)) {
               // write out js code for each row
               $style = $row4["style"];
               print "addSelectOption(form1,form1.styleMenu, \"$style\", \"$stlye\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.materialMenu.options.length = 0;\n";
       $result4 = mysql_query($query4);
     while ($row4 = mysql_fetch_array($result4)) {
          // get models for each make
          $style_ID = $row4["styleID"];
          $style= $row4["style"];
          print "if (style == \"$style\") { \n";
     
              $query5 = "SELECT materialID, material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
          $result5 = mysql_query($query5, $db) or die(mysql_error());
          while ($row5 = mysql_fetch_array($result5)) {
               // write out js code for each row
               $material = $row5["material"];
               print "addSelectOption(form1,form1.materialMenu, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeColor(control, form1) {\n";
     print "var color = control.value;\n";
     print "form1.colorMenu.options.length = 0;\n";
       $result5 = mysql_query($query5);
     while ($row5 = mysql_fetch_array($result5)) {
          // get models for each make
          $material_ID = $row5["materialID"];
          $material= $row5["material"];
          print "if (material == \"$material\") { \n";
     
              $query6 = "SELECT colorID, color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
          $result6 = mysql_query($query6, $db) or die(mysql_error());
          while ($row6 = mysql_fetch_array($result6)) {
               // write out js code for each row
               $color = $row6["color"];
               print "addSelectOption(form1,form1.colorMenu, \"$color\", \"$color\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
</script>
</head>
<body><form name="mainForm"><table><tr>
<td width="67">
  Catagory: </td><td width="187">
  <select name="catagoryMenu" onChange="changeCapacity(this,this.form);">
<option value="">Select Product Type</option>
<?php
     $result = mysql_query($query1, $db) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Capacity:</td><td>
<select name="capacityMenu" onChange="changeThread(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result2 = mysql_query($query2, $db) or die(mysql_error());
     while ($row2 = mysql_fetch_array($result2))
     {
?>
              <option value="">-- select a capacity --</option>
          <option value="<?=$row2["capacity"]?>"><?=$row2["capacity"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Thread:</td><td>
<select name="threadMenu" onChange="changeStyle(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result3 = mysql_query($query3, $db) or die(mysql_error());
     while ($row3 = mysql_fetch_array($result3))
     {
?>
          <option value="<?=$row3["thread"]?>"><?=$row3["thread"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Style:</td><td>
<select name="styleMenu" onChange="changeMaterial(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result4 = mysql_query($query4, $db) or die(mysql_error());
     while ($row4 = mysql_fetch_array($result4))
     {
?>
          <option value="<?=$row4["style"]?>"><?=$row4["style"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Material:</td><td>
<select name="materialMenu" onChange="changeColor(this,this.form);">
<option value="">Please select Product Type first</option>
<?php
     $result5 = mysql_query($query5, $db) or die(mysql_error());
     while ($row5 = mysql_fetch_array($result5))
     {
?>
          <option value="<?=$row5["material"]?>"><?=$row5["material"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Color:</td><td>
<select name="colorMenu">
     <option value="">Please select Product Type first</option>
</select>
</td></tr></table></form>
</body>
</html>
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
ok in that case what i do is try and run the queries manually in mysql and see what happens

SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID

so put that into mysql and change the $prodline_ID for whatever the actual value is


0
 

Author Comment

by:Kristina5
Comment Utility
no, all of my queries appear to be fine in mysql. Do I need to assign a default value for the variables in the begining? Right now I don't define $prodline_ID until the function code in the header.
0
 

Author Comment

by:Kristina5
Comment Utility
ok... that was the problem.. I intialized the variables in the begining and got rid of the error message... the database is still not pulling the data though
0
 

Author Comment

by:Kristina5
Comment Utility
This is what I have now. I have to run. I will be back on line tonight though so let me know if you have any brainstorms :)
Thanks!
k

http://www.krdesign4u.com/workingmenukrtest.php

<?php

// connect to db
      
// get results for 1st select box
$query1 = "select prodlineID,prodline from tbCatagory";
$result = mysql_query($query1, $db) or die("query1" . mysql_error());
$prodline_ID = 0;

$query2 = "SELECT capacityID,capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
$result2 = mysql_query($query2, $db) or die("query2" . mysql_error());
$capacity_ID = 0;

$query3 = "SELECT distinct threadID,thread FROM tbProducts WHERE prodlineID=$prodline_ID AND capacityID=$capacity_ID";
$result3 = mysql_query($query3, $db) or die("query3" . mysql_error());
$thread_ID = 0;

$query4 = "SELECT styleID,style FROM tbProducts WHERE prodlineID=$prodline_ID AND capacityID=$capacity_ID AND threadID=$thread_ID";
$result4 = mysql_query($query4, $db) or die("query4" . mysql_error());
$style_ID = 0;

$query5 = "SELECT materialID,material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
$result5 = mysql_query($query5, $db) or die("query5" . mysql_error());
$material_ID = 0;

$query6 = "SELECT colorID,color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
$result6 = mysql_query($query6, $db) or die("query6" . mysql_error());


?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodline == \"$prodline\") { \n";
     
              $query2 = "SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
          $result2 = mysql_query($query2, $db) or die(mysql_error());
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.threadMenu.options.length = 0;\n";
       $result2 = mysql_query($query2);
     while ($row2 = mysql_fetch_array($result2)) {
          // get models for each make
          $capacity_ID = $row2["capacityID"];
          print "if (capacity == \"$capacity\") { \n";
     
              $query3 = "SELECT 'threadID', 'thread' FROM 'tbProducts' WHERE capacityID=$capacity_ID";
          $result3 = mysql_query($query3, $db) or die(mysql_error());
          while ($row3 = mysql_fetch_array($result3)) {
               // write out js code for each row
               $thread = $row3["thread"];
               print "addSelectOption(form1,form1.threadMenu, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.styleMenu.options.length = 0;\n";
       $result3 = mysql_query($query3);
     while ($row3 = mysql_fetch_array($result3)) {
          // get models for each make
          $thread_ID = $row3["threadID"];
          $thread = $row3["thread"];
          print "if (thread == \"$thread\") { \n";
     
              $query4 = "SELECT styleID, style FROM tbProducts WHERE threadID=$thread_ID AND prodlineID=$prodline_ID";
          $result4 = mysql_query($query4, $db) or die(mysql_error());
          while ($row4 = mysql_fetch_array($result4)) {
               // write out js code for each row
               $style = $row4["style"];
               print "addSelectOption(form1,form1.styleMenu, \"$style\", \"$stlye\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.materialMenu.options.length = 0;\n";
       $result4 = mysql_query($query4);
     while ($row4 = mysql_fetch_array($result4)) {
          // get models for each make
          $style_ID = $row4["styleID"];
          $style= $row4["style"];
          print "if (style == \"$style\") { \n";
     
              $query5 = "SELECT materialID, material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
          $result5 = mysql_query($query5, $db) or die(mysql_error());
          while ($row5 = mysql_fetch_array($result5)) {
               // write out js code for each row
               $material = $row5["material"];
               print "addSelectOption(form1,form1.materialMenu, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeColor(control, form1) {\n";
     print "var color = control.value;\n";
     print "form1.colorMenu.options.length = 0;\n";
       $result5 = mysql_query($query5);
     while ($row5 = mysql_fetch_array($result5)) {
          // get models for each make
          $material_ID = $row5["materialID"];
          $material= $row5["material"];
          print "if (material == \"$material\") { \n";
     
              $query6 = "SELECT colorID, color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
          $result6 = mysql_query($query6, $db) or die(mysql_error());
          while ($row6 = mysql_fetch_array($result6)) {
               // write out js code for each row
               $color = $row6["color"];
               print "addSelectOption(form1,form1.colorMenu, \"$color\", \"$color\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
</script>
</head>
<body><table><tr><td><form name="mainForm"><table><tr>
<td width="67">
  Catagory: </td><td width="187">
  <select name="catagoryMenu" onChange="changeCapacity(this,this.form);" style="WIDTH: 210px" >
<option value=""> -- select -- </option>
<?php
     $result = mysql_query($query1, $db) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Capacity:</td><td>
<select name="capacityMenu" onChange="changeThread(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result2 = mysql_query($query2, $db) or die(mysql_error());
     while ($row2 = mysql_fetch_array($result2))
     {
?>
              <option value="">-- select a capacity --</option>
          <option value="<?=$row2["capacity"]?>"><?=$row2["capacity"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Thread:</td><td>
<select name="threadMenu" onChange="changeStyle(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result3 = mysql_query($query3, $db) or die(mysql_error());
     while ($row3 = mysql_fetch_array($result3))
     {
?>
          <option value="<?=$row3["thread"]?>"><?=$row3["thread"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Style:</td><td>
<select name="styleMenu" onChange="changeMaterial(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result4 = mysql_query($query4, $db) or die(mysql_error());
     while ($row4 = mysql_fetch_array($result4))
     {
?>
          <option value="<?=$row4["style"]?>"><?=$row4["style"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Material:</td><td>
<select name="materialMenu" onChange="changeColor(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result5 = mysql_query($query5, $db) or die(mysql_error());
     while ($row5 = mysql_fetch_array($result5))
     {
?>
          <option value="<?=$row5["material"]?>"><?=$row5["material"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Color:</td><td>
<select name="colorMenu" style="WIDTH: 210px">
     <option value=""></option>
</select>
</td></tr></table></form></td></tr></table>
</body>
</html>
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
the queries at the top dont need the where clause
as you want to pull back all results for each table.

so rename these variables so that you dont overwrite them later on.

$mainQuery1 instead of $query1;

and so on.
0
 

Author Comment

by:Kristina5
Comment Utility
Hi are you there by any chance?

I give up, it's not working at all now... I think I misunderstood something.

Here is my code:

<?php

// connect to db
$db=mysql_connect ("localhost", "krdesig_krowan01", "skimore") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("krdesig_Products");
      
// get results for 1st select box
$mainQuery1 = "select prodlineID,prodline from tbCatagory";
$result = mysql_query($mainQuery1, $db) or die("query1" . mysql_error());

$mainQuery2 = "SELECT capacityID,capacity FROM tbCapacity";
$result2 = mysql_query($mainQuery2, $db) or die("query2" . mysql_error());

$mainQuery3 = "SELECT threadID,thread FROM tbProducts";
$result3 = mysql_query($mainQuery3, $db) or die("query3" . mysql_error());

$mainQuery4 = "SELECT styleID,style FROM tbProducts";
$result4 = mysql_query($mainQuery4, $db) or die("query4" . mysql_error());

$mainQuery5 = "SELECT materialID,material FROM tbProducts";
$result5 = mysql_query($mainQuery5, $db) or die("query5" . mysql_error());

$mainQuery6 = "SELECT colorID,color FROM tbProducts";
$result6 = mysql_query($mainQuery6, $db) or die("query6" . mysql_error());


?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var prodline = control.value;\n";
     print "form1.capacityMenu.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get models for each make
          $prodline_ID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (prodline == \"$prodline\") { \n";
     
              $query2 = "SELECT capacityID, capacity FROM tbCapacity WHERE prodlineID=$prodline_ID";
          $result2 = mysql_query($query2, $db) or die(mysql_error());
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacityMenu, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.threadMenu.options.length = 0;\n";
       $result2 = mysql_query($query2);
     while ($row2 = mysql_fetch_array($result2)) {
          // get models for each make
          $capacity_ID = $row2["capacityID"];
          print "if (capacity == \"$capacity\") { \n";
     
              $query3 = "SELECT threadID, thread FROM tbProducts WHERE prodlineID=$prodline_ID AND capacityID=$capacity_ID";
          $result3 = mysql_query($query3, $db) or die(mysql_error());
          while ($row3 = mysql_fetch_array($result3)) {
               // write out js code for each row
               $thread = $row3["thread"];
               print "addSelectOption(form1,form1.threadMenu, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.styleMenu.options.length = 0;\n";
       $result3 = mysql_query($query3);
     while ($row3 = mysql_fetch_array($result3)) {
          // get models for each make
          $thread_ID = $row3["threadID"];
          $thread = $row3["thread"];
          print "if (thread == \"$thread\") { \n";
     
              $query4 = "SELECT styleID, style FROM tbProducts WHERE threadID=$thread_ID AND prodlineID=$prodline_ID";
          $result4 = mysql_query($query4, $db) or die(mysql_error());
          while ($row4 = mysql_fetch_array($result4)) {
               // write out js code for each row
               $style = $row4["style"];
               print "addSelectOption(form1,form1.styleMenu, \"$style\", \"$stlye\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.materialMenu.options.length = 0;\n";
       $result4 = mysql_query($query4);
     while ($row4 = mysql_fetch_array($result4)) {
          // get models for each make
          $style_ID = $row4["styleID"];
          $style= $row4["style"];
          print "if (style == \"$style\") { \n";
     
              $query5 = "SELECT materialID, material FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID";
          $result5 = mysql_query($query5, $db) or die(mysql_error());
          while ($row5 = mysql_fetch_array($result5)) {
               // write out js code for each row
               $material = $row5["material"];
               print "addSelectOption(form1,form1.materialMenu, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeColor(control, form1) {\n";
     print "var color = control.value;\n";
     print "form1.colorMenu.options.length = 0;\n";
       $result5 = mysql_query($query5);
     while ($row5 = mysql_fetch_array($result5)) {
          // get models for each make
          $material_ID = $row5["materialID"];
          $material= $row5["material"];
          print "if (material == \"$material\") { \n";
     
              $query6 = "SELECT colorID, color FROM tbProducts WHERE styleID=$style_ID AND prodlineID=$prodline_ID AND threadID=$thread_ID AND materialID=$material_ID";
          $result6 = mysql_query($query6, $db) or die(mysql_error());
          while ($row6 = mysql_fetch_array($result6)) {
               // write out js code for each row
               $color = $row6["color"];
               print "addSelectOption(form1,form1.colorMenu, \"$color\", \"$color\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
?>
<script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
</script>
</head>
<body><table><tr><td><form name="mainForm"><table><tr>
<td width="67">
  Catagory: </td><td width="187">
  <select name="catagoryMenu" onChange="changeCapacity(this,this.form);" style="WIDTH: 210px" >
<option value=""> -- select -- </option>
<?php
     $result = mysql_query($query1, $db) or die(mysql_error());
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Capacity:</td><td>
<select name="capacityMenu" onChange="changeThread(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result2 = mysql_query($query2, $db) or die(mysql_error());
     while ($row2 = mysql_fetch_array($result2))
     {
?>
              <option value="">-- select a capacity --</option>
          <option value="<?=$row2["capacity"]?>"><?=$row2["capacity"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Thread:</td><td>
<select name="threadMenu" onChange="changeStyle(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result3 = mysql_query($query3, $db) or die(mysql_error());
     while ($row3 = mysql_fetch_array($result3))
     {
?>
          <option value="<?=$row3["thread"]?>"><?=$row3["thread"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Style:</td><td>
<select name="styleMenu" onChange="changeMaterial(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result4 = mysql_query($query4, $db) or die(mysql_error());
     while ($row4 = mysql_fetch_array($result4))
     {
?>
          <option value="<?=$row4["style"]?>"><?=$row4["style"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Material:</td><td>
<select name="materialMenu" onChange="changeColor(this,this.form);" style="WIDTH: 210px" >
<option value=""></option>
<?php
     $result5 = mysql_query($query5, $db) or die(mysql_error());
     while ($row5 = mysql_fetch_array($result5))
     {
?>
          <option value="<?=$row5["material"]?>"><?=$row5["material"]?></option>
<?php
     }
?>
</select>
      </td>
    </tr>
<tr><td>Color:</td><td>
<select name="colorMenu" style="WIDTH: 210px">
     <option value=""></option>
</select>
</td></tr></table></form></td></tr></table>
</body>
</html>

The problem lies in the fact that the different scripts aren't comunicating with each other. Is there away to combine the individual scripts into one? I think that would fix all of my problems. I tried everything I could think of but was unsuccessful.
0
 

Author Comment

by:Kristina5
Comment Utility
or what about defining global variables?
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
ok hmm well i will try to make the code i have work for your database design, i will try and make a 3 level drop down and if i can get that to work with your db, then hopefully you will be able to extend it for the others.
0
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 500 total points
Comment Utility
ok ive changed my version to be more like yours and it nows has 3 select menus.

<?php

// connect to db
$connect = mysql_pconnect("localhost","root","");
mysql_select_db("test");

// get results for 1st select box
$categoryQuery = "select prodlineID,prodline from tbcategory";

// get results for 2nd select box
$capacityQuery = "select capacityID,capacity from tbcapacity";

$result = mysql_query($categoryQuery);
?>
<html>
<head>
      <title>test</title>
<?php
      print "<script language=\"JavaScript\">";
      print "function changeCapacity(control, form1) {\n";
      print "var category = control.value;\n";
      print "form1.capacity.options.length = 0;\n";
      while ($row = mysql_fetch_array($result)) {
            // get capacities for each prod
            $prodlineID = $row["prodlineID"];
            $prodline = $row["prodline"];
            print "if (category == \"$prodline\") { \n";
            $query2 = "select capacity from tbcapacity where prodlineID=$prodlineID";
            $result2 = mysql_query($query2);
            while ($row2 = mysql_fetch_array($result2)) {
                  // write out js code for each row
                  $capacity = $row2["capacity"];
                  print "addSelectOption(form1,form1.capacity, \"$capacity\", \"$capacity\");\n";
            }

            print "}\n"; // end if
      }
      print "}\n"; // end function
      print "</script>\n";
      mysql_free_result($result);
      mysql_free_result($result2);
?>
<?php
      $result = mysql_query($capacityQuery);
      print "<script language=\"JavaScript\">\n";
      print "function changeThread(control, form1) {\n";
      print "var capacity = control.value;\n";
      print "form1.thread.options.length = 0;\n";
      while ($row = mysql_fetch_array($result)) {
            // get thread for each capacity
            $capacityID = $row["capacityID"];
            $capacity = $row["capacity"];
            print "if (capacity == \"$capacity\") { \n";
            $query2 = "select thread from tbthread where capacityID=$capacityID";
            $result2 = mysql_query($query2);
            while ($row2 = mysql_fetch_array($result2)) {
                  // write out js code for each row
                  $thread = $row2["thread"];
                  print "addSelectOption(form1,form1.thread,\"$thread\",\"$thread\");\n";
            }
            print "}\n"; // end if
      }
      print "}\n"; // end function
      print "</script>\n";
      mysql_free_result($result);
      //mysql_free_result($result2);
?>
      <script language="JavaScript">
            function addSelectOption(form1,selectobj, val, atr) {
                  var index = selectobj.options.length;
                  form1.elements[selectobj.name].options[index]= new Option(atr,val);
            }
      </script>
</head>
<body>
<form name="mainForm">
Category:<select name="category" onChange="changeCapacity(this,this.form);">
<option value="">Select a category</option>
<?php
      $result = mysql_query($categoryQuery);
      while ($row = mysql_fetch_array($result))
      {
?>
            <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
      }
?>
</select>
<br />
Capacity:
<select name="capacity" onChange="changeThread(this,this.form);">
      <option value="">Please select category first</option>
</select>
<br />
Thread:
<select name="thread">
      <option value="">Please select capacity first</option>
</select>
</form>
</body>
</html>

// here is the db i used
#
# Table structure for table `tbcapacity`
#

CREATE TABLE tbcapacity (
  capacityID int(11) NOT NULL default '0',
  prodlineID int(11) NOT NULL default '0',
  capacity varchar(80) NOT NULL default ''
) TYPE=MyISAM;

#
# Dumping data for table `tbcapacity`
#

INSERT INTO tbcapacity VALUES (1, 1, '1/4 oz');
INSERT INTO tbcapacity VALUES (2, 1, '1/2 oz');
INSERT INTO tbcapacity VALUES (3, 1, '7/8 oz');
INSERT INTO tbcapacity VALUES (4, 1, '1 oz');
INSERT INTO tbcapacity VALUES (5, 1, '1 1/2 oz');
# --------------------------------------------------------

#
# Table structure for table `tbcategory`
#

CREATE TABLE tbcategory (
  prodlineID int(11) NOT NULL default '0',
  prodline varchar(80) NOT NULL default ''
) TYPE=MyISAM;

#
# Dumping data for table `tbcategory`
#

INSERT INTO tbcategory VALUES (1, 'Jars');
INSERT INTO tbcategory VALUES (2, 'Caps');
INSERT INTO tbcategory VALUES (3, 'Liners');
INSERT INTO tbcategory VALUES (4, 'Wax Containers');
INSERT INTO tbcategory VALUES (5, 'Jewelry Basket');
# --------------------------------------------------------

#
# Table structure for table `tbthread`
#

CREATE TABLE tbthread (
  threadID int(11) NOT NULL auto_increment,
  capacityID int(11) NOT NULL default '0',
  thread varchar(80) NOT NULL default '',
  PRIMARY KEY  (threadID)
) TYPE=MyISAM;

#
# Dumping data for table `tbthread`
#

INSERT INTO tbthread VALUES (1, 1, '33 mm');
INSERT INTO tbthread VALUES (2, 1, '38 mm');
INSERT INTO tbthread VALUES (3, 1, '43 mm');
0
 

Author Comment

by:Kristina5
Comment Utility
Hi, I am getting the following error messages:


Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/krdesig/public_html/test.php on line 40

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/krdesig/public_html/test.php on line 41

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/krdesig/public_html/test.php on line 65


All I did was test it on my site, i haven't actually changed anything yet
0
 

Author Comment

by:Kristina5
Comment Utility
Hi, I am getting the following error messages:


Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/krdesig/public_html/test.php on line 40

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/krdesig/public_html/test.php on line 41

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/krdesig/public_html/test.php on line 65


All I did was test it on my site, i haven't actually changed anything yet
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
but unless you changed your database to be exactly like mine then it wont work straight away.
there is probably a problem with the queries as i have used different field names or different field types.
0
 

Author Comment

by:Kristina5
Comment Utility
ok I'll try it again. THANKS! Sorry I know this is such a pain in the *** !! :)
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
thats ok.

just look at the queries and see if they make sense, try them out in mysql to make sure they work etc
0
 

Author Comment

by:Kristina5
Comment Utility
ok it is working with one exception, is there a way to have a option selected in the 2nd and third boxes (not from the database) ie --select--
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
i dont understand :(
0
 

Author Comment

by:Kristina5
Comment Utility
ok, this is the result of the six boxes....

http://www.parkwayjars.com/test2.php

it is still getting stuck at the thread query... I have it checking more than one variable is that a problem? The query is fine in mysql.

<?php

// connect to db
$db=mysql_connect ("localhost", "krdesig_krowan01", "skimore") or die ('I cannot connect to the database because: ' . mysql_error());
      mysql_select_db ("krdesig_Products");
      
// get results for 1st select box
$catagoryQuery = "select prodlineID,prodline from tbCatagory";

// get results for 2nd select box
$capacityQuery = "select capacityID,capacity from tbCapacity";

// get results for 3rd select box
$threadQuery = "select threadID,thread from tbProducts";

// get results for 4th select box
$styleQuery = "select styleID,style from tbProducts";

// get results for 5th select box
$materialQuery = "select materialID,material from tbProducts";

$result = mysql_query($catagoryQuery);
?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var catagory = control.value;\n";
     print "form1.capacity.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $prodlineID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (catagory == \"$prodline\") { \n";
          $query2 = "select capacity from tbCapacity where prodlineID=$prodlineID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacity, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     mysql_free_result($result2);
?>
<?php
       $result = mysql_query($capacityQuery);
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.thread.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $capacityID = $row["capacityID"];
          $capacity = $row["capacity"];
          print "if (capacity == \"$capacity\") { \n";
          $query2 = "select thread from tbProducts where prodlineID=$prodlineID and capacityID=$capacityID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $thread = $row2["thread"];
               print "addSelectOption(form1,form1.thread, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
<?php
       $result = mysql_query($threadQuery);
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.style.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $styleID = $row["styleID"];
          $style = $row["style"];
          print "if (style == \"$style\") { \n";
          $query2 = "select style from tbProducts where prodlineID=$prodlineID and capacityID=$capacityID and threadID=$threadID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $style = $row2["style"];
               print "addSelectOption(form1,form1.style, \"$style\", \"$style\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
<?php
       $result = mysql_query($styleQuery);
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.material.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $materialID = $row["materialID"];
          $material = $row["material"];
          print "if (material == \"$material\") { \n";
          $query2 = "select material from tbProducts where prodlineID=$prodlineID and capacityID=$capacityID and threadID=$threadID and styleID=$styleID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $material = $row2["material"];
               print "addSelectOption(form1,form1.material, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
<?php
     $result = mysql_query($materialQuery);
     print "<script language=\"JavaScript\">\n";
     print "function changeColor(control, form1) {\n";
     print "var material = control.value;\n";
     print "form1.material.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get thread for each capacity
          $colorID = $row["colorID"];
          $color = $row["color"];
          print "if (color == \"$color\") { \n";
          $query2 = "select color from tbProducts where prodlineID=$prodlineID and capacityID=$capacityID and threadID=$threadID and styleID=$styleID and materialID=$materialID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $color = $row2["color"];
               print "addSelectOption(form1,form1.color,\"$color\",\"$color\");\n";
          }
          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
     <script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
     </script>
</head>
<body>
<form name="mainForm">
catagory:<select name="catagory" onChange="changeCapacity(this,this.form);">
<option value="">Select a catagory</option>
<?php
     $result = mysql_query($catagoryQuery);
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
<br />
Capacity:
<select name="capacity" onChange="changeThread(this,this.form);">
     <option value="">Please select catagory first</option>
</select>
<br />
Thread:
<select name="thread">
     <option value="">Please select capacity first</option>
</select>
<br />
Style:
<select name="style">
     <option value="">Please select capacity first</option>
</select>
<br />
Material:
<select name="material">
     <option value="">Please select capacity first</option>
</select>
<br />
Color:
<select name="color">
     <option value="">Please select capacity first</option>
</select>
</form>
</body>
</html>

0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
the fact that you want to include the previous box choices in the queries makes this a hell of a lot harder :(

e.g. where capacityID=$capacityID and prodlineID=$prodlineID

:( :(
0
 

Author Comment

by:Kristina5
Comment Utility
:/ why, what does it entail? :(
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
im not sure yet, but its a brain teaser for sure.
i will need to think about it, it would be lot easier if the page was getting recalled because then you would know the choices the person made, but you cant know in advance what choices the person will make so you would have to write all the queries for all possibities, now with 6 boxes each with many possible choices thats a lot of queries!! im thinking maybe we could cheat a bit.

what if we had a hidden frame, and we passed some variables to it from the main frame (which holds the 6 drop downs) then that hidden frame could load a dynamic page with the variables we passed in, it would then generate the javascript needed and populate the drop downs in the main frame. this of course is not simple and we would probably need to start from scratch, but its all i can think of at the moment.

0
 

Author Comment

by:Kristina5
Comment Utility
hey I was just wondering if were there and if you had any new brainstorms? I am not sure how well the frames thing would work on my site, but I could make it work if I had too...

0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
no not had any new brainstorms, your problem is a lot harder than i thought.
the way i do drop down menus is to have them related to each other in series.
as in you must select 1 before you can select 2.
but from what your saying you want all choices to be available. but of course that wont
work because the values stored in the drop downs need to be related to the choices you make.
0
 

Author Comment

by:Kristina5
Comment Utility
do you know anything about global variables?

I was thinking that that might work?

I found this example on the internet but am not exactly sure how or where to imcorporate it.

"Global Variables
Local variables are declared within the body of a function, and can only be used within that function. This is usually no problem, since when another function is called, all required data is passed to it as arguments. Alternatively, a variable can be declared globally so it is available to all functions. Modern programming practice recommends against the excessive use of global variables. They can lead to poor program structure, and tend to clog up the available name space.

A global variable declaration looks normal, but is located outside any of the program's functions. This is usually done at the beginning of the program file, but after preprocessor directives. The variable is not declared again in the body of the functions which access it. "

<?php
$myMessage = "I'm the original message";

function changeMessage()
{
  global $myMessage; # This will change the value!
  $myMessage = "Now I'm different!";
  return $myMessage;
}

changeMessage();
print "$myMessage";
?>

OUTPUT:
Now I'm different!

 
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
maybe im not understanding what you want exactly.

can you explain again, specially about why you want all the drop down to be filled and selectable
0
 

Author Comment

by:Kristina5
Comment Utility
sure... I am designing a product search as you know, each product catagory has specific items and each item has specific options. Not all options are available for all items and that is why I want to create a dependent menu system so that the user can narrow down the search each time. and find only the products that he or she is looking for. To do this however I have to be able to compare all the users selctions with my database.
0
 

Author Comment

by:Kristina5
Comment Utility
by the way I want to give you more points because you have been helping me so much. If I give you the points and open up a new 500 point ticket will you still help me? :)
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
sure i will still help you, hopefully we can get something that works.

when i get some time, prob at weekend, ic an try and do that frame solution.
0
 

Author Comment

by:Kristina5
Comment Utility
0
 

Author Comment

by:Kristina5
Comment Utility
Hey,

OK I changed my search for the moment so that it isn't checking multiple varibles as I really just need to get it up at this point. I will fix the details later.

http://www.parkwayjars.com/test4.php

It is working with the exception of the material box...

once you select an option it apears to reset or sometime because the select box is blank...

can you take a quick look at it... What am I missing?

<?php

// connect to db

// get results for 1st select box
$catagoryQuery = "select distinct prodlineID,prodline from tbCatagory";

// get results for 2nd select box
$capacityQuery = "select distinct capacityID,capacity from tbCapacity";

// get results for 3rd select box
$threadQuery = "select distinct threadID,thread from tbProducts";

// get results for 4th select box
$styleQuery = "select distinct styleID,style from tbProducts";

// get results for 5th select box
$materialQuery = "select distinct materialID,material from tbProducts";

$result = mysql_query($catagoryQuery);
?>
<html>
<head>
     <title>test</title>
<?php
     print "<script language=\"JavaScript\">";
     print "function changeCapacity(control, form1) {\n";
     print "var catagory = control.value;\n";
     print "form1.capacity.options.length = 0;\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $prodlineID = $row["prodlineID"];
          $prodline = $row["prodline"];
          print "if (catagory == \"$prodline\") { \n";
          $query2 = "select DISTINCT capacity from tbCapacity where prodlineID=$prodlineID";
          $result2 = mysql_query($query2);
              print "addSelectOption(form1,form1.capacity, \"\", \"-- select --\");\n";
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
                     $capacity = $row2["capacity"];
               print "addSelectOption(form1,form1.capacity, \"$capacity\", \"$capacity\");\n";
          }

          print "}\n"; // end if

     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     mysql_free_result($result2);
?>
<?php
       $result = mysql_query($capacityQuery);
     print "<script language=\"JavaScript\">";
     print "function changeThread(control, form1) {\n";
     print "var capacity = control.value;\n";
     print "form1.thread.options.length = 0;\n";
       print "addSelectOption(form1,form1.thread, \"\", \"-- select --\");\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $capacityID = $row["capacityID"];
          $capacity = $row["capacity"];
          print "if (capacity == \"$capacity\") { \n";
          $query2 = "select DISTINCT thread from tbProducts where capacityID=$capacityID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $thread = $row2["thread"];
               print "addSelectOption(form1,form1.thread, \"$thread\", \"$thread\");\n";
          }

          print "}\n"; // end if
             
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
<?php
       $result = mysql_query($threadQuery);
     print "<script language=\"JavaScript\">";
     print "function changeStyle(control, form1) {\n";
     print "var thread = control.value;\n";
     print "form1.style.options.length = 0;\n";
       print "addSelectOption(form1,form1.style, \"\", \"-- select --\");\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $threadID = $row["threadID"];
          $thread = $row["thread"];
          print "if (thread == \"$thread\") { \n";
          $query2 = "select DISTINCT style from tbProducts where threadID=$threadID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $style = $row2["style"];
               print "addSelectOption(form1,form1.style, \"$style\", \"$style\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
<?php
       $result = mysql_query($styleQuery);
     print "<script language=\"JavaScript\">";
     print "function changeMaterial(control, form1) {\n";
     print "var style = control.value;\n";
     print "form1.material.options.length = 0;\n";
       print "addSelectOption(form1,form1.material, \"\", \"-- select --\");\n";
     while ($row = mysql_fetch_array($result)) {
          // get capacities for each prod
          $styleID = $row["styleID"];
          $style = $row["style"];
          print "if (style == \"$style\") { \n";
          $query2 = "select DISTINCT material from tbProducts where styleID=$styleID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $material = $row2["material"];
               print "addSelectOption(form1,form1.material, \"$material\", \"$material\");\n";
          }

          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     //mysql_free_result($result2);
?>
<?php
     $result = mysql_query($materialQuery);
     print "<script language=\"JavaScript\">\n";
     print "function changeColor(control, form1) {\n";
     print "var material = control.value;\n";
     print "form1.material.options.length = 0;\n";
       print "addSelectOption(form1,form1.color, \"\", \"-- select --\");\n";
     while ($row = mysql_fetch_array($result)) {
          // get thread for each capacity
          $materialID = $row["materialID"];
          $material = $row["material"];
          print "if (material == \"$material\") { \n";
          $query2 = "select DISTINCT color from tbProducts where materialID=$materialID";
          $result2 = mysql_query($query2);
          while ($row2 = mysql_fetch_array($result2)) {
               // write out js code for each row
               $color = $row2["color"];
               print "addSelectOption(form1,form1.color,\"$color\",\"$color\");\n";
          }
          print "}\n"; // end if
     }
     print "}\n"; // end function
     print "</script>\n";
     mysql_free_result($result);
     mysql_free_result($result2);
?>
     <script language="JavaScript">
          function addSelectOption(form1,selectobj, val, atr) {
               var index = selectobj.options.length;
               form1.elements[selectobj.name].options[index]= new Option(atr,val);
          }
     </script>
</head>
<body>

<table width="85%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
<form name="mainForm"  action="productmaster.php" method="get" enctype="multipart/form-data">
<table><tr><td>
  Category: </td><td>
  <select name="catagory" style="WIDTH: 150px" onChange="changeCapacity(this,this.form); return false;" >
<option value="">Select a catagory</option>
<?php
     $result = mysql_query($catagoryQuery);
     while ($row = mysql_fetch_array($result))
     {
?>
          <option value="<?=$row["prodline"]?>"><?=$row["prodline"]?></option>
<?php
     }
?>
</select>
            </td>
          </tr><tr><td>
Capacity:</td><td>
<select name="capacity" style="WIDTH: 150px" onChange="changeThread(this,this.form); return false;" >
     <option value="">Please select catagory first</option>
</select>
            </td>
          </tr><tr><td>
Thread:</td><td>
<select name="thread" style="WIDTH: 150px" onChange="changeStyle(this,this.form); return false;" >
     <option value="">Please select capacity first</option>
</select>
            </td>
          </tr><tr><td>
Style:</td><td>
<select name="style" style="WIDTH: 150px" onChange="changeMaterial(this,this.form); return false;" >
     <option value="">Please select capacity first</option>
</select>
            </td>
          </tr><tr><td>
Material:</td><td>
<select name="material" style="WIDTH: 150px" onChange="changeColor(this,this.form); return false;" >
     <option value="">Please select capacity first</option>
</select>
            </td>
          </tr><tr><td>
Color:</td><td>
<select name="color" style="WIDTH: 150px" onChange="submit();">
     <option value="">Please select capacity first</option>
</select></td></tr></table>
</form></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>

0
 

Author Comment

by:Kristina5
Comment Utility
the other thing is if you change one of the higher up boxes I would like the select boxes below to reset themselves. Is that possible?

0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
do you mean reset to be empty? im sorry ive not been back in touch but so busy at the moment.
if it was a 5 minute thing id have done it already but it will take me a while to sort it out
0
 

Author Comment

by:Kristina5
Comment Utility
Please no worries... I totally understand!!! :) The most important thing that I am trying to sort out is why the material box is over writing itself... If you go to the test page you will notice that their is no material value after you fill out the form (in the select box and in the URL... I have it "getting" the data)

the reset question can wait until later...

I tried to insert another function to see if that would correct it and it did, the material box was working fine, but the color box stopped pulling data. I must not be ending the script series correctly...

Just when you get a minute (I know you are really busy, so if you don't, don't worry I will continue to play with it)... I think it is really close though... thanks!
0
 
LVL 6

Expert Comment

by:jkna_gunn
Comment Utility
you have typo in the change colour function
it is deleteing the material drop down not the color one.

form1.material.options.length = 0;
should be
form1.color.options.length = 0;
0
 

Author Comment

by:Kristina5
Comment Utility
YOU ARE THE BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

THANK YOU THANK YOU THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now