Jump to content

Multi drop-down menu


MannyG

Recommended Posts

Hey all!

 

The basic premise of what I would like to do is create a drop-down menu (within a form so I can send those values to another page to query them into a database) that upon being clicked narrows down to another drop-down menu which finally narrows down to one more drop down menu. I have the first two working, however the third drop-down does not work. Also I want to know, I am using a form for each of these instances...and another form below this code for textfield input, each dropdown has it's own form, so this file has 4 forms. Is it possible to send all the form data to the same page and retrieve each result still? Here is my code...

 

<?php

//grabs codeline from dropdown
$getcodeline = $_GET['codeline'];
//grabs build from dropdown
$getbuild = $_GET['build'];


	 echo "<center><h1><b>Add Info</b></h1></br></center>";
	 print "\t<form id='sort'>\n";
	//Codeline drop down menu (1st drop down, where initial selection occurs)
	$distinctcodeline = mysql_query("SELECT DISTINCT version FROM build");

		echo "<select name='codeline' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">";
		echo "<option>Select Codeline</option>";

			while($search=mysql_fetch_array($distinctcodeline)){

				echo"<option>".$search['version']."</option>";
				echo "</br>";

		}
	echo "</select>";
	print "\t</form>\n";

                       //here the second dropdown menu starts and it checks if anything has been selected...this actually works...
		if (isset($getcodeline)){

			//select bundle based on codeline selected...
			$specificBundle = mysql_query("SELECT DISTINCT bundle FROM build WHERE version = '$getcodeline'");
			 print "\t<form id='sort'>\n";
			echo "<select name='bundle' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">";
			echo "<option>Select Bundle</option>";

			while($searching=mysql_fetch_array($specificBundle)){

				echo"<option>".$searching['bundle']."</option>";
				echo "</br>";

		}
			echo "</select>";
			print "\t</form>\n";

		}

		if (isset($getbuild)){

			//this is the third one, now the query is a little harder, but it works in mysql and so it should work fine... i am passing the variable $getbuild through it
			$specificDevice = mysql_query("SELECT DISTINCT build.bundle, build_device_test.build_id, build.build_id, build_device_test.deviceID, devices.devicename, devices.deviceID FROM build, devices, build_device_test WHERE (build.build_id = build_device_test.build_id) AND (devices.deviceID = build_device_test.deviceID) AND (build.bundle = '$getbuild')");
			print "\t<form id='sorted'>\n";

			echo "<select name='device' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">";
			echo "<option>Select Device</option>";

			while($devicesearching=mysql_fetch_array($specificDevice)){

				echo"<option>".$devicesearching['devicename']."</option>";
				echo "</br>";

		}
		echo "</select>";
		print "\t</form>\n";
			}	

?>

 

After this the normal form starts. I would like to add, the variable that is called '$getbuild' I tried echoing it (to see if the selection shows from dropdown menu 2) but it did not appear, so I am not sure if that may be one of the problems or not o__O

 

Any help is greatly appreciated, thank you!

Link to comment
Share on other sites

As to your first problem:

 

$getbuild = $_GET['build'];

But you define the name of the select as "bundle" - not build:

 

echo "<select name='bundle' ...

The browser will only submit form values for the form that was told to submit. You can keep everything in the same form by altering your if statements by adding an "else" clause:

 

if (isset($getcodeline)){
....
}
else {
print "\t</form>\n";
}

 

Then you need to delete all your "print "\t</form>\n";" where they appear currently (except in the last if statement), and remove the "print "\t<form id='sort'>\n";" within the if statements.

Link to comment
Share on other sites

Sorry yeah I noticed the first error few minutes after posting, forgot to update...however for the part where I make it all form, I did that and it show's correctly except the last drop down still does not show. Also when I echo out $getbuild it does not return the value selected, returns nothing...but $getcodeline returns whatever value that is selected.

Link to comment
Share on other sites

Okay here is the weird thing...it works under these conditions (by works I mean all three menus show and it displays the $getbuild value...

 

When I select an item from the first dropdown...

 

Then the second dropdown appears and I select an item from there...

 

Then I go back to the first dropdown and select a different value, it seems to send these values (it shows in URL since I am using $_GET) AND with these values sent and registered, the THIRD dropdown appears.

 

 

Ideas..?

Link to comment
Share on other sites

<?php
//grabs codeline from dropdown
$getcodeline = $_GET['version'];
echo "<center><h1><b>Add Info</b></h1></br></center>";
	 print "\t<form id='sort'>\n";
	//Codeline drop down menu
	$distinctcodeline = mysql_query("SELECT DISTINCT version FROM build");

		echo "<select name='version' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">";
		echo "<option>Select Codeline</option>";

			while($search=mysql_fetch_array($distinctcodeline)){

				echo"<option>".$search['version']."</option>";
				echo "</br>";

		}
	echo "</select>";
	echo $getcodeline;

		$getbuild = $_GET['bundle'];

		if (isset($getcodeline)){

			//select bundle based on codeline selected...
			$specificBundle = mysql_query("SELECT DISTINCT bundle FROM build WHERE version = '$getcodeline'");

			echo "<select name='bundle' onchange=\"document.getElementById('sorted').submit()\" onselect=\"select()\">";
			echo "<option>Select Bundle</option>";

			while($searching=mysql_fetch_array($specificBundle)){

				echo"<option>".$searching['bundle']."</option>";
				echo "</br>";

		}
			echo "</select>";
			echo $getbuild;


		}

		if (isset($getbuild)){

			//select device based on bundle selected...
			$specificDevice = mysql_query("SELECT DISTINCT build.bundle, build_device_test.build_id, build.build_id, build_device_test.deviceID, devices.devicename, devices.deviceID FROM build, devices, build_device_test WHERE (build.build_id = build_device_test.build_id) AND (devices.deviceID = build_device_test.deviceID) AND (build.bundle = '$getbuild')");


			echo "<select name='device' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">";
			echo "<option>Select Device</option>";

			while($devicesearching=mysql_fetch_array($specificDevice)){

				echo"<option>".$devicesearching['devicename']."</option>";
				echo "</br>";

		}
		echo "</select>";
		}
		else {
		print "\t</form>\n";
			}	
?>

 

This is what it look's like now.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.