Hierarchial browsing through drop-down menus

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clangro
Forum Newbie
Posts: 7
Joined: Thu Jul 07, 2005 9:48 am
Location: Georgia

Hierarchial browsing through drop-down menus

Post by clangro »

I currently have a test website I'm working on for a very basic search page for my company. It works well enough, but I need to add some functionality so that:

- People search hierarchially via drop-downs. So lets say we were using a map as an example. You'd select a state in the 1st drop-down. Then the county in the next drop down. Then the city in the next drop-down. Then the block, then the address.

- It needs to show what has been selected after it has been submitted, that way people won't forget what they have searched for.

TIA!


http://acscable.com/test/test.php

Code: Select all

<html>
	<head>  
		<title>PHP Test</title>
	</head>
	<body>
		<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
		<select name="equipment_type">
			<option value="junk">-------------------</option>
			<option value="%">All Equipment Types</option>
			<option value="E911">E911 Cables</option>
		</select>
		<select name="project">
			<option value="junk">-------------------</option>
			<option value="%">All Projects</option>
			<option value="Ericsson">Ericsson</option>
		</select>
		<INPUT TYPE=SUBMIT VALUE="Submit">
		<?
			$username="acscable_client";
			$password="cat7";
			$database="acscable_tmobile";
			mysql_connect(localhost,$username,$password);
			@mysql_select_db($database) or die( "Unable to select database");
			$query="select * from tmobile where equipment_type like '".$_POST["equipment_type"]."' AND project like '".$_POST["project"]."'";
			$result=mysql_query($query);
			$num=mysql_numrows($result);
			mysql_close();
			$i=0;
			while ($i < $num) 
				{
					$region=mysql_result($result,$i,"region");
					$manu_part_num=mysql_result($result,$i,"manu_part_num");
					$acs_part_num=mysql_result($result,$i,"acs_part_num");
					$equipment_type=mysql_result($result,$i,"equipment_type");
					$project=mysql_result($result,$i,"project");
					$description=mysql_result($result,$i,"description");
					$picture=mysql_result($result,$i,"photo");
					echo "<br><br><img src=\"$picture\"></img><br><br><b>Region:</b> $region <br><b>Manufacturer Part #:</b> $manu_part_num<br><b>ACS Part #:</b> $acs_part_num<br><b>Equipment Type</b>: $equipment_type<br><b>Project:</b> $project<br><b>Description:</b> $description<br><hr><br>";
					$i++;
				}
		?>
	</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what are you wanting? help, or someone to these feature additions for you? :?
clangro
Forum Newbie
Posts: 7
Joined: Thu Jul 07, 2005 9:48 am
Location: Georgia

Post by clangro »

feyd wrote:what are you wanting? help, or someone to these feature additions for you? :?
Someone to explain how to do this.

Right now all I've got is a crappy "All-in-One" PHP/MySQL/Apache book with no web coding experience. I've tried to google for some information, but most form tutorials I've found don't have what I want to do and are for input boxes instead of selecting pre-existing values.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well, CoderGoblin's tutorial on database driven select boxes can be adapted to do what you wish pretty easily. You can either have it resubmit the page to get a new drop list (most compatible, least memory instensive on the browser, more taxing on the server; although not much), use xmlhttp to pull the individual select boxes as they become "available" (advanced technique), or send all possible sets of select boxes and switch them (like CoderGoblin's tutorial does) ...
clangro
Forum Newbie
Posts: 7
Joined: Thu Jul 07, 2005 9:48 am
Location: Georgia

Post by clangro »

I actually decided that I don't need a hierarchy search structure that bad, since there is so little data to actually filter.

However, I do need the drop down boxes to "remember" what was selected when a query was submitted.

By default right now it selects -------. If you want to search for "All Equipment Types" and "Ericson", when you select them and hit "submit", it automatically resets those drop downs back to -------. I need it to keep the values you submitted in the drop down after you submit, so if you search for Ericson and All Equipment Type and hit submit, Ericson and All Equipment Types will be the values selected in the drop down box after you hit submit.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

we've gone over dynamic "selected" status, but here's the basics: create a loop that creates the select box, compare the value you will place in the box with the select made (if any). As you should always, have a default value it'll look for it no value was sent.
Post Reply