Help in two dropdown form

Can anyone help me how to synchronize the two dropdown field…
I have two tables 1 for the Category other for SubCategory.

The output should be, if i have a field for Category.

CatID CatName
1 Door
2 Window

and for SubCategory

CatID SubCatName
1 Knob
1 Lock
2 Glass
2 Lock

Now how do i synchronize it in the dropdown field base on the CatID.

[google]linked|chained select boxes[/google]


Can anyone help me how to populate the dropdownlist and get the id of the data.
this is my works just fine if i delete the hidden text but i need the hidden text to pass the variable of the said data…Thanks…

<form action='catsubsamp.php' method='post'>
		<td align='right'><b>Category<font color=red>*</font>: </b></td>	
					echo "<select class='user' name='user' tabindex='1'>";
					echo "<option></option>";
						echo "<option value='$user1[CatName]'>".$user1['CatName']."</option>"; 
							echo "<input type='hidden' value='$user1[Catid]' name='catidname'>";
					echo '</select>';

			<input type='text' name='cat'>
			<input type='submit' name='save' value='Save'>

thanks for the linked…it is applicable if i just choose the ID of the said Category for the subcategory…i’m just confused…Thanks

It looks as if you are asking how to do a join on two tables, but as I am not 100% what you mean - show us the output of these 2 sql queries;

describe category;

describe subcategory;

<? echo "<option value=\\"" . $user1['CatId'] . "\\">" . $user1['CatName'] . "</option>"; ?>
echo "<option value='" . $user1['Catid'] . "'>" . $user1['CatName']. "</option>" . PHP_EOL ; 

If you are using auto-generated id numbers as Private Keys on a table, one generally passes the id of the chosen cat as the returned value of a select, as indicated above.

Off Topic:

Threads merged