View Full Version : I need help please with 3 dependent drop downs
capirucho
09-23-2010, 11:48 PM
I have two drop downs working. When I add a third drop down it does not work. What am I doing wrong?
1st dropdown > Select State
2nd dropdown > Select City
3rd dropdown > Select Zip
You can see my test page at:
http://www.ronaldfigueroa.com/test/dynamic_dropdowns_test.php
PHP File is here:
http://www.ronaldfigueroa.com/test/dynamic_dropdowns_test.zip
SQL file for table im using:
http://www.ronaldfigueroa.com/test/ZIPCITYSTATE.zip
Any help is greatly appreciated. I've been stuck on this for a while so I come to you FORUM GODS for help.
Much appreciated.
Jason Byrnes
09-24-2010, 07:54 AM
Theres a couple of small problems here:
1) the rsListOfCities dynamic array is set to pass the zip as child id, use the city instead
2) rsListOfZipcodes dynamic array is set to use the city as the parent ID, but it is not included in the recordset:
$query_rsListOfZipcodes = "SELECT cityStatZip_tbl.zip FROM cityStatZip_tbl ORDER BY cityStatZip_tbl.zip";
change that to include the city:
$query_rsListOfZipcodes = "SELECT cityStatZip_tbl.city, cityStatZip_tbl.zip FROM cityStatZip_tbl ORDER BY cityStatZip_tbl.zip";
capirucho
09-24-2010, 02:14 PM
thank you very much that worked.
I do notice a problem now:
It seems that Dynamic Dropdown code is not passing the state value along.
So for example when I select
1>> Select State: California
2>> Select City: Torrance
3>> Select Zipcodes: [This list of Zipcodes should be populated only by the zipcodes that are in Torrance, California]
What seems to be happening is that on 3rd select I'm getting "all" zipcodes with any city "torrance" (As is the case there is a Torrance in Pennsylvania). But what I need is to be specific to the state that was selected? Is this something on my end or something that can't be done with the Dynamcic Dropdown Extension?
Once again thank you very much.
Dave Buchholz
09-25-2010, 08:06 AM
Working off the original file you posted you need to make these changes:
1. The query for rsListOfZipcodes needs to be changed like so:
$query_rsListOfZipcodes = "SELECT cityStatZip_tbl.zip, cityStatZip_tbl.city FROM cityStatZip_tbl ORDER BY cityStatZip_tbl.city";
2. Select the Create Dynamic Array (rsListOfCities) entry in the Server Behaviours Panel and change the entries as follows:
Parent ID field: statename
Child ID field: statename
Child Text field: city
3. Select the Create Dynamic Array (rsListOfZipcodes) entry in the Server Behaviours Panel and change the entries as follows:
Parent ID field: city
Child ID field: city
Child Text field: zip
I would also using Group By rather than SELECT DISTINCT in you other recordsets like so:
$query_rsStates = "SELECT cityStatZip_tbl.statename FROM cityStatZip_tbl GROUP BY cityStatZip_tbl.statename ORDER BY cityStatZip_tbl.statename";
$query_rsListOfCities = "SELECT cityStatZip_tbl.city, cityStatZip_tbl.statename FROM cityStatZip_tbl GROUP BY cityStatZip_tbl.city ORDER BY cityStatZip_tbl.city";
That should get you going.
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.