我需要一个显示以下内容的脚本:国家 > 地区(很多)> 这个地区的城市(也很多)。尝试,但不能 :( 帮助
$get_all = $db->query("SELECT * FROM ".PREFIX."_shop_cities WHERE type='0'"); # Берем страны
while($row = $db->get_row($get_all)){
$get_regions = $db->query("SELECT * FROM ".PREFIX."_shop_cities WHERE god='$row[id]' AND type='1'"); # Регионы
while($row2 = $db->get_row($get_regions)){
$get_cities = $db->query("SELECT * FROM ".PREFIX."_shop_cities WHERE god='$row2[id]' AND type='2'"); # города
while($row3 = $db->get_row($get_cities)){
$tpl->load_template("eshop/citylist.tpl");
$tpl->set("{city_name}", "<li>".$row3["name_ru"]."</li>");
$tpl->compile("cities");
$tpl->clear();
}
$tpl->load_template("eshop/regionslist.tpl");
$tpl->set("{region_name}", $row2["name_ru"]);
$tpl->set("{cities}", $tpl->result["cities"]);
$tpl->compile("regions");
$tpl->clear();
}
$tpl->load_template("eshop/countrylist.tpl");
$tpl->set("{name_country}", $row["name_ru"]);
$tpl->set("{regions}", $tpl->result["regions"]);
$tpl->compile("citylist");
$tpl->clear();
}
最佳答案
我试着这样做:
$get_all = $db->query("SELECT a.name_ru as Country, b.name_ru AS Region, c.name_ru AS City FROM dle_shop_cities AS a JOIN dle_shop_cities AS b ON a.id = b.god AND b.type = 1 JOIN dle_shop_cities AS c ON b.id = c.god AND c.type = 2"); # Берем страны
while($row = $db->get_row($get_all)){
$tpl->load_template("eshop/citylist.tpl");
$tpl->set("{city_name}", "<li>".$row["City"]."</li>");
$tpl->compile("cities");
$tpl->clear();
$tpl->load_template("eshop/regionslist.tpl");
$tpl->set("{region_name}", $row[Region]);
$tpl->set("{cities}", $tpl->result["cities"]);
$tpl->compile("regions");
$tpl->clear();
$tpl->load_template("eshop/countrylist.tpl");
$tpl->set("{name_country}", $row["Country"]);
$tpl->set("{regions}", $tpl->result["regions"]);
$tpl->compile("citylist");
$tpl->clear();
}
没有成功, Россия Новосибирская область Омск Россия Новосибирская область Омск Новосибирская область Омск Новосибирск Россия Новосибирская область Омск Новосибирская область Омск Новосибирск Московская область Омск Новосибирск 摩斯卡瓦 请再次帮助
关于php - 在 while 循环中,结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31099945/