We help IT Professionals succeed at work.
Get Started

Using choice in a dropdown menu to populate second dropdown menu

543 Views
Last Modified: 2013-12-12
I have a simple MySQL database with fields of squadID, event, squadInfo.  I want to have a dropdown where the user selects a choice for event, and that would populate a dropdown for squadInfo where the only contents are those associated with that type of event.

Right now the search is being conducted by populating the squadInfo dropdown with all of the possible choices.  I have attached the code for that page below.
<?php require_once('Connections/connMSUSBC.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_connMSUSBC, $connMSUSBC);
$query_rsOpenSquads = "SELECT * FROM opensquads09";
$rsOpenSquads = mysql_query($query_rsOpenSquads, $connMSUSBC) or die(mysql_error());
$row_rsOpenSquads = mysql_fetch_assoc($rsOpenSquads);
$totalRows_rsOpenSquads = mysql_num_rows($rsOpenSquads);
?><link href="/squadtables.css" rel="stylesheet" type="text/css" />
<table width="630" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td width="3%">&nbsp;</td>
    <td width="97%"><div align="center">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><div align="center">
              <h3>2009 MSUSBC OPEN CHAMPIONSHIP<br />
                SQUAD ASSIGNMENTS<br />
                <br />
            </h3>
              </div></td>
        </tr>
        <tr>
          <td><table width="100%" border="0">
            <tr>
              <td><hr /></td>
            </tr>
            <tr>
              <td><div align="center">Please select your Search Criteria:</div></td>
            </tr>
            <tr>
              <td><hr /></td>
            </tr>
            
            <tr>
              <td>
              <form id="squadInfo" name="squadInfo" method="get" action="squadassignopenresults2009.php">
                <label>
                <br />
                  Date and Time of Squad:
                  <select name="squadInfo2" id="squadInfo2">
                    <option value="" <?php if (!(strcmp("", $row_rsOpenSquads['squadInfo']))) {echo "selected=\"selected\"";} ?>>Please Select Your Squad</option>
                    <?php
do {  
?>
                    <option value="<?php echo $row_rsOpenSquads['squadID']?>"<?php if (!(strcmp($row_rsOpenSquads['squadID'], $row_rsOpenSquads['squadInfo']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsOpenSquads['squadInfo']?></option>
                    <?php
} while ($row_rsOpenSquads = mysql_fetch_assoc($rsOpenSquads));
  $rows = mysql_num_rows($rsOpenSquads);
  if($rows > 0) {
      mysql_data_seek($rsOpenSquads, 0);
	  $row_rsOpenSquads = mysql_fetch_assoc($rsOpenSquads);
  }
?>
                    </select> 
                 &nbsp;&nbsp; 
                 <input type="submit" name="Search" id="Search" value="Search" />
                      </label>
                                         <br />
                                         <br />
              </form></td>
            </tr>
            <tr>
              <td><hr /></td>
            </tr>
            <tr>
              <td>

Open in new window

Comment
Watch Question
PHP Programmer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE