php - 在 while 循环中,结果错误

标签 php mysql while-loop

我需要一个显示以下内容的脚本:国家 > 地区(很多)> 这个地区的城市(也很多)。尝试,但不能 :( 帮助

$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/

相关文章:

php - 如何在 SQL 中插入保留字为 "from"的记录?

javascript - 如何创建一个函数来接受输入并测试它是否是回文?

python - 尝试除了递归或 while 循环?

php - 如何将已删除的数据移动到 Yii 2 中的另一个表?

javascript - 动态填充搜索框(选择) Bootstrap jquery中的选项

php - 使用多复选框将具有相同 id 的多个项目添加到表中

mysql - 联合不存在的表时出现问题

PHP While 循环只显示最后一行

php - 自动化测试生成?

php - 向两个表中插入数据?