• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

PHP Forms - Nested Drop downs?

AndyT_uk

n00b
Joined
Sep 27, 2005
Messages
18
Hi all,

Little while since i've done any PHP but am needing to create a couple of pages for a project.

Basically what I want to do is to have 2/3 drop down boxes on a page which are all populated from entries in 2/3 different tables.

When a value in the first drop down box is selected, it'll pull the relevant fields from the next table and put them into the next drop down box and so on.

Possibly a little easier to explain in context. Drop down 1 will select an Office, once selected the applicable buildings for that office are available in Drop down 2. From those options, once a selection is made, the applicable floors for that building are shown in drop down 3.

Hopefully someone can understand that and point me in the right direction as i've never really looked at nested drop-downs etc.

Currently at the moment its 4 different tables, sites / buildings / floors / ports

Sites - siteID, siteName
Buildings - buildingID, siteID, buildingName
Floors - floorID, buildingID, floorName
Ports - port ID, floorID ......lots more detailed fields

eventually all the relevant info in the ports field will be displayed once the selections have been made from the sites/buildings and floors drop-down boxes.

It may be that that db structure needs re-working, its been a good few years since i covered DB design

Any help or pointers on this would be greatly appreciated,

Cheers,

Andy
 
Here is a quick snippet from a website I did. Hopefully this helps.
PHP:
<?php
echo '
		<form method="POST" name="addFrm">
		<tr>
			<td align="right">Select the match division</td>
			<td align="left">
			<select name="division" onChange="putDivUrl(this.value);">
				<option value=""'.$selected.'>Select..</option>
			';
			unset($selected);
			$division = mysql_query("SELECT `name` FROM `divisions` ORDER BY `name` ASC");
			while($d = mysql_fetch_array($division))
			{
				$selected = "";
				if(isset($_GET['division']) && $_GET['division'] == $d['name'])
				{
					$selected = " selected";
				}
				echo '<option value="'.$d['name'].'"'.$selected.'>'.$d['name'].'</option>';
			}
		echo '
			</select>
			</td>
		</tr>';
?>
 
Back
Top