Challenging code
Posted: Tue Dec 16, 2003 8:17 am
I need a dynamic generated list of countries, states, cities and stores. This is my code and is V-E-R-Y slow.
Can you optimize this code? Any Thought?
----------------------------------------------------------------
Look at this scenario:
Countries: 150
States: 50 (each Country)
Cities: 100 (each State)
Stores: 25 (each City)
Thanks in advance.
Can you optimize this code? Any Thought?
Code: Select all
$e_Deposit = "<option selected value=''>All</option>\n";
$get_countries=mysql_query("SELECT * from countries ORDER BY NameCountry", $db);
while ($mycountry = mysql_fetch_array($get_countries))
{
$e_Deposit.= "<option style="color: blue;" value=c" . $mycountryї"IDCountry"] . ">" . chop($mycountryї"NameCountry"]) . "</option>\n";
$get_states=mysql_query("SELECT * from states WHERE Country=$mycountryїIDCountry] ORDER BY NameState", $db);
while ($mystate=mysql_fetch_array($get_states))
{
$e_Deposit.= "<option style="color: red;" value=s" . $mystateї"IDState"] . "> " . chop($mystateї"NameState"]) . "</option>\n";
$get_citys=mysql_query("SELECT * from citys WHERE State=$mystateїIDState] ORDER BY NameCity", $db);
while ($mycitys= mysql_fetch_array($get_citys))
{
$e_Deposit.= "<option style="color: darkgreen;" value=c" . $myvitysї"IDCity"] . "> " . chop($mycitysї"NameCity"]) . "</option>\n";
$get_store = mysql_query("SELECT * FROM stores WHERE City= $mycitysїIDCity] ORDER BY NameStore ASC",$db);
while ($mystore= mysql_fetch_array($get_store))
{
$e_Deposit.= "<option value=t" . $mystoreї"IDStore"] . "> " . chop($myrowї"NameStore"]) . "</option>\n";
}
}
}
}Look at this scenario:
Countries: 150
States: 50 (each Country)
Cities: 100 (each State)
Stores: 25 (each City)
Thanks in advance.