Hi folks!
I have this wierd situation, and I\'m not exactly sure how to make it work - I am hacking my way through this MySQL and PHP stuff learning as I go.
Goal: Have a Javascript drop-down menu that a user selects a state, then that auto-populates a different drop-down menu with the cities that can be chosen.
This Javascript form works perfect alone. However, I want to make the back end database powered, and I need to create the Javascript code with PHP so I can use it in several places and when a new city is added as an option, then I won\'t have to go manually change each one.
Here is the Javascript part that needs to be created:
group[0][0]=new Option(\"Choose State...\",\"/sellers/index.php#choose\")
group[0][1]=new Option(\" \",\"/sellers_new.php#choose\")
group[0][2]=new Option(\" \",\"/sellers_new.php#choose\")
group[0][3]=new Option(\" \",\"/sellers_new.php#choose\")
group[1][0]=new Option(\"Choose...\",\"/sellers_new.shtml#choose\")
group[1][1]=new Option(\"Birmingham\",\"/sellers/index2.php?state= AL&city=BHM\")
group[1][2]=new Option(\"Florence\",\"/sellers/index2.php?state=AL&city=FLO\")
group[1][3]=new Option(\"Mobile\",\"/sellers/index2.php?state=AL&city=MOB\")
group[1][4]=new Option(\"Montgomery\",\"/sellers/index2.php?state=AL&city=MGM\")
group[2][0]=new Option(\"Choose...\",\"/sellers_new.shtml#choose\")
group[2][1]=new Option(\"Palm Beach\",\"/sellers/index2.php?state=FL&city=PBX\")
group[2][2]=new Option(\"Panama City\",\"/sellers/index2.php?state=FL&city=PFN\")
group[2][3]=new Option(\"Pensacola\",\"/sellers/index2.php?state=FL&city=PNS\")
group[3][0]=new Option(\"Choose...\",\"/sellers_new.shtml#choose\")
group[3][1]=new Option(\"Charlotte\",\"/sellers/index2.php?state=NC&city=CLT\")
Ok, now here is my attempt at making it db powered:
<?
$db_states = mysql_connect(\"---site---\", \"---username---\",\"---pass---\");
mysql_select_db(\"---site---\",$db_states);
$result = mysql_query(\"SELECT DISTINCT state FROM areas ORDER BY state\",$db_states);
while ($states = mysql_fetch_array($result)) {
setvar group_states == \"group_states\"+1;
echo \'group[$group1][0]=new Option(\"Choose...\",\"/sellers_new.shtml#choose\")\' . \"\n\";
$db_cities = mysql_connect(\"---site---\", \"---username---\",\"---pass---\");
mysql_select_db(\"---site---\",$db_cities);
$result2 = mysql_query(\"SELECT city, city_initials, state_initials FROM areas WHERE state=$states[\'state\'] ORDER BY city\",$db_cities);
while ($cities = mysql_fetch_array($result2)) {
setvar group_cities == \"group_cities\"+1;
echo \'group[$group_states][$group_cities]=new Option(\"\' . $cities[\'city\'] . \'\",\"/sellers/index2.php?state=\' . $cities[\'state_initials\'] . \'&city=\' . $cities[\'city_initials\'] . \'\")\' . \"\n\";
}
}
?>
The PHP doesn\'t get past the first WHILE statement - it gives a parse error, and I can\'t figure out why.
If anyone could help, I would really really appreciate it. And if I am approaching this all wrong, let me know that, too.
Thanks in advance!