Jump to content

dependent dropdown help?


Codeman0013

Recommended Posts

Hello, i'm working on a website and i have 4 dropdown's that are on a page and i want to make them dependent. Right now i have them set to pull from the database but i want it set to based on what they select on number 1 it populates number 2 and number 2 populates 3 and 3 does 4 and so on. Can someone take a look at my code and help me to achieve this as i have never done it before and would appreciate any help at all..

[code]<?php require_once('Connections/conn_dj.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_industry = "SELECT * FROM tbl_industry ORDER BY industry_name ASC";
$rs_industry = mysql_query($query_rs_industry, $conn_dj) or die(mysql_error());
$row_rs_industry = mysql_fetch_assoc($rs_industry);
$totalRows_rs_industry = mysql_num_rows($rs_industry);

mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_productcategory = "SELECT * FROM tbl_productcat  ORDER BY tbl_productcat.productCat_name";
$rs_productcategory = mysql_query($query_rs_productcategory, $conn_dj) or die(mysql_error());
$row_rs_productcategory = mysql_fetch_assoc($rs_productcategory);
$totalRows_rs_productcategory = mysql_num_rows($rs_productcategory);

mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_product = "SELECT * FROM tbl_products ORDER BY tbl_products.products_name";
$rs_product = mysql_query($query_rs_product, $conn_dj) or die(mysql_error());
$row_rs_product = mysql_fetch_assoc($rs_product);
$totalRows_rs_product = mysql_num_rows($rs_product);

mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_outsidena = "SELECT * FROM intl_countries ORDER BY intl_countries.name";
$rs_outsidena = mysql_query($query_rs_outsidena, $conn_dj) or die(mysql_error());
$row_rs_outsidena = mysql_fetch_assoc($rs_outsidena);
$totalRows_rs_outsidena = mysql_num_rows($rs_outsidena);

mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_state = "SELECT * FROM tbl_states ORDER BY tbl_states.`state`";
$rs_state = mysql_query($query_rs_state, $conn_dj) or die(mysql_error());
$row_rs_state = mysql_fetch_assoc($rs_state);
$totalRows_rs_state = mysql_num_rows($rs_state);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DICKEY-john Corporation | Distributors</title>
<link href="_lib/sub.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="Distributor, Sales, Purchase, U.S., International" />
<meta name="description" content="Enter your zip or postal code to find the DICKEY-john distributor nearest you." />
</head>

<body>
<div id="black">&nbsp;</div>
<div id="siteContainer">
<?php include("_inc/topNav.inc"); ?>
<div id="headerContainer">Distributors</div>
<div class="divContainer"><div class="horizDiv"></div><img src="/_img/divEnd.png" alt="div" height="16" width="4" align="right" /></div>
<div id="contentContainer">
<div id="fullContainer">
<div id="stretchCrumbs">
<a href="/index.php">Home</a>
&#187; <a class="high" href="/distributors/">Distributors</a>
</div>
<h1>Distributors</h1>
<p>Search for DICKEY-john distributers by specifying any combonation of the<br />
following classifications: industry, product category, product, and state.</p>
<br />

<br />




<h2>North America</h2>

  <table class="setTbl listTbl" width="90%" cellpadding="0" cellspacing="0" border="0">
    <tr><td>Industry:</td><td>
    <select name="industry" id="center" onchange="javascript:document.centerform.submit()">
      <option value="">Select an Industry...</option>
      <?php do { ?>
      <option value="<?php echo $row_rs_industry['industry_name']; ?>"><?php echo $row_rs_industry['industry_name']; ?></option>
     
      <?php } while ($row_rs_industry = mysql_fetch_assoc($rs_industry)); ?></td></tr>
        </select>
    <tr><td width="125">Product Category: </td>  <td>
    <select name="prodcat" id="center" onchange="javascript:document.centerform.submit()">
      <option value="">Select a product category...</option>
      <?php do { ?>
      <option value="<?php echo $row_rs_productcategory['productCat_name']; ?>"><?php echo $row_rs_productcategory['productCat_name']; ?></option>
     
      <?php } while ($row_rs_productcategory = mysql_fetch_assoc($rs_productcategory)); ?></td></tr>
        </select>
    <tr>
    <td>Product:</td><td>
    <select name="prod" id="center" onchange="javascript:document.centerform.submit()">
      <option value="">Select a product...</option>
      <?php do { ?>
      <option value="<?php echo $row_rs_product['products_name']; ?>"><?php echo $row_rs_product['products_name']; ?></option>
      <?php } while ($row_rs_product = mysql_fetch_assoc($rs_product)); ?>
      </td></tr>
        </select>
    <td>State:</td>
          <td> <select name="state" id="center" onchange="javascript:document.centerform.submit()">
      <option value="">Select a state...</option>
      <?php do { ?>
      <option value="<?php echo $row_rs_state['state']; ?>"><?php echo $row_rs_state['state']; ?></option>
      <?php } while ($row_rs_state = mysql_fetch_assoc($rs_state)); ?>
      </td></tr>
        </select></td>
      </tr>
    <tr><td>&nbsp;</td><td><input class="PythonButton" type="submit" value="Find" name="{Button_Name}"></td></tr>
          </table>
    </form>

<br />
<h2>Outside North America </h2>
<table class="setTbl listTbl" width="90%" cellpadding="0" cellspacing="0" border="0">
<tr><td>  <select name="outna" id="center" onchange="javascript:document.centerform.submit()">
      <option value="">Select a country...</option>
      <?php do { ?>
      <option value="<?php echo $row_rs_ousidena['name']; ?>"><?php echo $row_rs_outsidena['name']; ?></option>
      <?php } while ($row_rs_outsidena = mysql_fetch_assoc($rs_outsidena)); ?>
      </td></tr>
      </select></td>
    </tr></td></tr>
      </table>
</form>
</div>
</div>
<?php include("_inc/footer.inc"); ?>
</body>
</html>
<?php
mysql_free_result($rs_industry);

mysql_free_result($rs_productcategory);

mysql_free_result($rs_product);

mysql_free_result($rs_outsidena);

mysql_free_result($rs_state);
?>

[/code]
Link to comment
Share on other sites

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

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...

Important Information

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