这是我的桌子...
Locations
__________________________________________________________
ID Location Region Country
1 Newmarket Ontario Canada
2 Barrie Ontario Canada
3 New York City New York US
4 Buffalo New York US
5 Vancouver British Columbia Canada
Regions
__________________________________________________________
ID Region Country
1 Ontario Canada
2 New York US
3 British Columbia Canada
Countries
__________________________________________________________
ID Country
1 Canada
2 US
这些表比这大得多,我正在尝试将列表加载到一个可扩展的列表中,就像这样......
造型没问题,我已经整理好了。我只是试图在一个快速的 MySQL 查询中加载所有这些信息。这就是我目前在 PHP 中所拥有的,它需要使用这些 while 循环进行大量查询。(以我的桌子大小)
<div id="listContainer">
<ul id="expList">
<?php
$countries = $conn->query("SELECT * FROM countries ORDER BY country ASC");
while($crow = mysqli_fetch_array($countries))
{
$cname = $crow['country'];
$regions = $conn->query("SELECT * FROM regions WHERE country = '$cname' ORDER BY region ASC")
?>
<li class="country">
<?php echo $cname; ?>
<ul class="undercountry">
<?php
while($rrow = mysqli_fetch_array($regions))
{
echo "<li>";
$rname = $rrow['region'];
echo $rname;
?>
<ul>
<?php
$locations = $conn->query("SELECT * FROM locations WHERE region = '$rname' AND country = '$cname' ORDER BY location ASC");
while($lrow = mysqli_fetch_array($locations)){
$lname = $lrow['location'];
echo $lname;
}
?>
</ul>
<?php
echo "</li>";
}
?>
</ul>
</li>
<?php
}
?>
</ul>
</div>
有没有办法做到这一点?只使用位置表和组是可以的,但我不太擅长编写选择查询。