Dynamic Select Lists - 1st Selection Effects 2nd!

From: Date: Thu, 31 Jul 2008 16:40:06 +0000
Subject: Dynamic Select Lists - 1st Selection Effects 2nd!
Groups: php.general 
Request: Send a blank email to php-general+get-277539@lists.php.net to get a copy of this message
Ave, What I have is two Select (Drop-Down) lists (State & County) and I'm populating them from a mySQL table. What I want is when the user selects the State from the State List, the County List should only pull out counties associated with that State. Now I know that you can create such an effect using Javascript or AJAX and have nothing to do with PHP/mySQL - and I was able to accomplish that - but only for lists where you could define data manually. I'm not able to accomplish this at all with Lists that are pulling out option data from a mySQL table. I'm also giving the User the opportunity to add as many State/County combinations as possible in a box. 'tis my code: <!-- *********** STATE/COUNTY BOX ************ --> <TR> <TD CLASS="blackText">State: </TD> <TD CLASS="blackText"><SELECT NAME="d_state"> <?php do { ?> <OPTION VALUE="<?php echo $row_D_STATE['STATE']?>"><?php echo $row_D_STATE['STATE']?></OPTION> <?php } while ($row_D_STATE = mysql_fetch_assoc($D_STATE)); $rows = mysql_num_rows($D_STATE); if($rows > 0) { mysql_data_seek($D_STATE, 0); $row_D_STATE = mysql_fetch_assoc($D_STATE); } ?> </SELECT> </TD> </TR> <TR> <TD CLASS="blackText">County: </TD> <TD CLASS="blackText"> <SELECT NAME="d_county"> <OPTION VALUE="ALL" SELECTED>All</OPTION> <?php do { ?> <OPTION VALUE="<?php echo $row_D_COUNTY['COUNTY']?>"><?php echo $row_D_COUNTY['COUNTY']?></OPTION> <?php } while ($row_D_COUNTY = mysql_fetch_assoc($D_COUNTY)); $rows = mysql_num_rows($D_COUNTY); if($rows > 0) { mysql_data_seek($D_COUNTY, 0); $row_D_COUNTY = mysql_fetch_assoc($D_COUNTY); } ?> </SELECT> <INPUT NAME="add_btn_1" TYPE="button" VALUE="[+] Add" onClick="document.AD_INVENTORY_FORM.d_state_county.value+=document.AD_INVENTORY_FORM.d_state.value+'/'+document.AD_INVENTORY_FORM.d_county.value+'\n';"> </TD> </TR> <TR> <TD CLASS="blackText" COLSPAN="2"><TEXTAREA NAME="d_state_county" COLS="26" ROWS="3"></TEXTAREA></TD> </TR> <!-- *********** STATE/COUNTY BOX ************ --> I'm not able to understand exactly how to manipulate the SQL Query or otherwise force the 2nd Select List to only show records that match the selected State. Any pointers? --- Rahul Sitaram Johari Founder, Internet Architects Group, Inc. [Email] sleepwalker@rahulsjohari.com [Web] http://www.rahulsjohari.com

« previous php.general (#277539) next »