Click here to Skip to main content
15,894,252 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I first would like to state I am not a web developer but have been put in a position to complete a simple inventory system for my company. Secondly I have googled this question all afternoon and have had no luck finding anything that I can wade through and apply to my specific application.
I want to populate a serial number dropdown box (dropdown2) with only the serial numbers of the correct component types based on the componentType chosen in the componentType dropdown box(dropdown1). Below is the needed portions of the tables and the code I have currently. Dropdown1 is displaying the proper values but I need dropdown2 to change dynamically as dropdown1 is altered. Thank you in advance for any help or guidance available.

TABLE Components
idComponent INT(Primary KEY)
serialComponent VARCHAR
idComponentType INT (Foreign Key to ComponentType)

TABLE ComponentType
idComponentType INT
nameComponentType VARCHAR

PHP
$queryComponentType = "SELECT idComponentType,nameComponentType FROM ComponentType";

//Execute query, or return an error message if there is a problem.
$result1 = mysql_query($queryComponentType) or die(mysql_error());

$dropdown1 = "<select nameComponentType = 'ComponentType'>";

while($row=mysql_fetch_assoc($result1)){
	$dropdown1 .="\r\n<option value='{$row['nameComponentType']}'>
                     {$row['nameComponentType']}</option>";
}

$dropdown1 .= "\r\n</select>";

echo"<p>Component Types: ".$dropdown1 ."</p>"; 
	
$querySerialComponent = "SELECT serialComponent,idComponentType FROM Components";

//Execute query, or return an error message if there is a problem.
$result2 = mysql_query($querySerialComponent) or die(mysql_error());

$dropdown2 = "<select serialComponent = 'Components'>";

while($row=mysql_fetch_assoc($result2)){
       $dropdown2 .="\r\n <option value='{$row['serialComponent']}'> 
                    $row['serialComponent']}<;/option>";
}

$dropdown2 .= "\r\n</select>";

echo"<p>Component Serial Numbers: ".$dropdown2 ."</p>"; 
Posted

1 solution

Hi Friend,

I know only in asp.net, I am explaining it from my point of view.

for dropdown list 1 make autopostback="true"
Search for anything like autopostback for dropdownlist in php

In the code behind provide the code in dropdownlistbox 1 selected index changed event.

Thank you,

Ganesh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900