multi select boxes

I have 4 selection boxes on a page.

Select 1 holds the parent data

Select 2 hold data 1 level down from select 1 and so on.

I have it working but have to submit the form for each select change to take effect.


<?php $sql=("SELECT * FROM Somewhere WHERE Parent = '1' ORDER by 'name'"); $parent = mysql_query($sql, $con) or die(mysql_error()); $parent_row = mysql_fetch_assoc($par);
	echo $parent_Row['name'];
<?php $sql1=("SELECT * FROM Somewhere WHERE Parent = '$select1' ORDER by 'name'"); $parent1 = mysql_query($sql1, $con) or die(mysql_error()); $parent1_row = mysql_fetch_assoc($par);
	echo $parent1_Row['name'];


The above is just an example to give you an idea. Is there a way that the boxes will refresh on change.

I know this can be done with jave but need the information pulling from an sql database.

Does anyone have any suggestions

that depends on the amount of data. If u are able to load all data at once u may use simple javascript, otherwise u have to use a automatc refresh or AJAX.

something like:

<select name="select1" onchange="document.getElementById(this.value).style.display='block'">
<option value="1">first</option>
<option value="2">second</option>

<div id="1" style="display:hidden">
<select name="select2[1]">...</select>
<div id="2" style="display:hidden">
<select name="select2[2]">...</select>

or just:

<form id="myform">
<select name="select1" onchange="document.getElementById('myform').submit()">

Thanks for your reply and help. It all seems to be working now, the codes a bit long winded though

Above HTML

<?php mysql_select_db($database_connect, $connect); $query_Countries = "SELECT * FROM destinations WHERE destinations.parent ='1'"; $Countries = mysql_query($query_Countries, $connect) or die(mysql_error()); $row_Countries = mysql_fetch_assoc($Countries); $totalRows_Countries = mysql_num_rows($Countries); mysql_select_db($database_connect, $connect); $query_Countries_Echo = "SELECT * FROM destinations WHERE'$box1'"; $Countries_Echo = mysql_query($query_Countries_Echo, $connect) or die(mysql_error()); $row_Countries_Echo = mysql_fetch_assoc($Countries_Echo); $totalRows_Countries_Echo = mysql_num_rows($Countries_Echo); mysql_select_db($database_connect, $connect); $query_States = "SELECT * FROM destinations WHERE destinations.parent='$box1'"; $States = mysql_query($query_States, $connect) or die(mysql_error()); $row_States = mysql_fetch_assoc($States); $totalRows_States = mysql_num_rows($States); mysql_select_db($database_connect, $connect); $query_States_Echo = "SELECT * FROM destinations WHERE'$box2'"; $States_Echo = mysql_query($query_States_Echo, $connect) or die(mysql_error()); $row_States_Echo = mysql_fetch_assoc($States_Echo); $totalRows_States_Echo = mysql_num_rows($States_Echo); mysql_select_db($database_connect, $connect); $query_Regions = "SELECT * FROM destinations WHERE destinations.parent='$box2'"; $Regions = mysql_query($query_Regions, $connect) or die(mysql_error()); $row_Regions = mysql_fetch_assoc($Regions); $totalRows_Regions = mysql_num_rows($Regions); mysql_select_db($database_connect, $connect); $query_Regions_Echo = "SELECT * FROM destinations WHERE destinations.parent='$box3'"; $Regions_Echo = mysql_query($query_Regions_Echo, $connect) or die(mysql_error()); $row_Regions_Echo = mysql_fetch_assoc($Regions_Echo); $totalRows_Regions_Echo = mysql_num_rows($Regions_Echo); ?>


Inbetween Body Tags


<?php echo $row_Countries_Echo['name'] ?> <?php do { ?> ><?php echo $row_Countries['name']?> <?php } while ($row_Countries = mysql_fetch_assoc($Countries)); $rows = mysql_num_rows($Countries); if($rows > 0) { mysql_data_seek($Countries, 0); $row_Countries = mysql_fetch_assoc($Countries); } ?> <?php if($box1 < 1) { ?>Select State<?php ; } else { ?><?php echo $row_States_Echo['name'] ?><?php ; } ?> <?php do { ?> ><?php echo $row_States['name']?> <?php } while ($row_States = mysql_fetch_assoc($States)); $rows = mysql_num_rows($States); if($rows > 0) { mysql_data_seek($States, 0); $row_States = mysql_fetch_assoc($States); } ?> <?php if($box2 < 1) { ?>Select Region<?php ; } else { ?><?php echo $row_Regions_Echo['name'] ?><?php ; } ?> <?php do { ?> ><?php echo $row_Regions['name']?> <?php } while ($row_Regions = mysql_fetch_assoc($Regions)); $rows = mysql_num_rows($Regions); if($rows > 0) { mysql_data_seek($Regions, 0); $row_Regions = mysql_fetch_assoc($Regions); } ?> [/php]

Does anyone know of a way to shorten the code!!!

the length of the code looks ok.

of cause u could shorten it down, but it would get les readable.

one thing u could do is to use a function like to build the selects.

I think I’ll leave it now its workng. Thanks for your help with the AJAX thingy.

I thought Ajax was a place in Holand, you learn something new everyday on here

Once again thanks, its much appreciated

Sponsor our Newsletter | Privacy Policy | Terms of Service