Dynamic Drop Down Box

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat May 19, 2012 8:40 am

Dynamic Drop Down Box

Postby fuller » Mon May 21, 2012 11:57 am

Hello all. I am pretty new to PHP programming and mysql but so far have actually had a pretty good go at teaching myself but I have finally hit a wall that I just can not comprehend. Yes, I have used google. (A LOT) but I can't not find an example that I can comprehend. I'm hoping the experts here can help me out. I have 3 tables. (2 data tables, and 1 junction table) I have a drop down that will dynamically create the table query from the first drop down but I have no idea how to make the second drop down box dynamically dependent on the first then to also update my results. Here is my code and honestly I'm not really sure how the script portion of it works that is creating the table. Any help would very much be appreciated.

Here is the code for the main page.

Code: Select all

require 'connection.php';
require 'variable_set.php';
require 'auth_check.php';


<script type="text/javascript">
function showProject(str)
if (str=="")
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)


<select name="Project" onchange="showProject(this.value)">
<option value="">Select a project:</option>                 
    $projquery="SELECT Projects.id_Project,Projects.`Project` FROM Projects";
    $projresult=mysql_query($projquery) or die ("Query to get data from firsttable failed:".mysql_error());
    while ($projrow=mysql_fetch_array($projresult)){
        echo "<option value=$idproject>$project</option>\n";                                                                   
<div id="txtHint"><b>Project Status will be listed here.</b></div>
<br />


Get Project Code

Code: Select all


$_SESSION['$q'] = $q;

//if ($a != null) {
//   unset($a);
//   }

require 'connection.php';
require 'variable_set.php';
require 'auth_check.php';

//$sql="SELECT * FROM user WHERE id = '".$q."'";
$sql="SELECT Projects.Project AS `Project`
     , Assemblies.Assembly AS `Assembly`
     , Ditmco_Programming_Status.Programming_Status AS `Ditmco Programming`
     , Ditmco_Harness_Status.Harness_Status AS `Ditmco Adapters`
     , Torque_Programming_Status.Programming_Status AS `Torque Programming`
     , Torque_Adapter_Status.Adapter_Status AS `Torque Adapters`
     , Tooling_Status.Tooling AS Tooling
ON Project_Status.Project = Projects.id_Project
INNER JOIN Assemblies
ON Project_Status.Assembly = Assemblies.id_Assembly
INNER JOIN Project_Has_Assembly
ON Project_Has_Assembly.Project = Projects.id_Project AND Project_Has_Assembly.Assembly = Assemblies.id_Assembly
INNER JOIN Ditmco_Programming_Status
ON Project_Status.Ditmco_Programming = Ditmco_Programming_Status.id_Programming_Status
INNER JOIN Ditmco_Harness_Status
ON Project_Status.Ditmco_Harnesses = Ditmco_Harness_Status.id_Harness_Status
INNER JOIN Torque_Programming_Status
ON Project_Status.Torque_Program = Torque_Programming_Status.id_Programming_Status
INNER JOIN Torque_Adapter_Status
ON Project_Status.Torque_Adapters = Torque_Adapter_Status.id_Adapter_Status
INNER JOIN Tooling_Status
ON Project_Status.Tooling = Tooling_Status.id_Tooling
  Projects.id_Project ='$q'
, Assemblies.Assembly";

$result = mysql_query($sql);

echo "<table border='1'>
<th>Ditmco Programming</th>
<th>Ditmco Adapters</th>
<th>Torque Programming</th>
<th>Torque Adapters</th>

while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['Project'] . "</td>";
  echo "<td>" . $row['Assembly'] . "</td>";
  echo "<td>" . $row['Ditmco Programming'] . "</td>";
  echo "<td>" . $row['Ditmco Adapters'] . "</td>";
  echo "<td>" . $row['Torque Programming'] . "</td>";
  echo "<td>" . $row['Torque Adapters'] . "</td>";
  echo "<td>" . $row['Tooling'] . "</td>";
  echo "</tr>";
  echo "</tr>";
echo "</table>";


The query for the Assembly would look something like this:

Code: Select all

    $assyquery="SELECT Assemblies.Assembly FROM Project_Has_Assembly
INNER JOIN Assemblies
ON Project_Has_Assembly.Assembly = Assemblies.id_Assembly
  Project_Has_Assembly.Project = '$idproject'";
    $assyresult=mysql_query($assyquery) or die ("Query to get data from firsttable failed:".mysql_error());
    while ($assyrow=mysql_fetch_array($assyresult)){
        echo "<option value=$idassembly>$assembly</option>\n";                                                                   

What I would really like to do now is have a second drop down for Assembly that would be generated when the project is chosen. Which would in turn update the table.

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 4 guests