我的数据库看起来像这样...显示城市和地点的名称的列表,这些城市
ID,城市,名字
1,阿霍,肚子亩
2,高山,高山村庄
3,Apache的交界处,失去了荷兰人
4,Apache的交界处,巴特菲尔德
5,Apache的交界处,本森
6,比斯比,女王矿
...等等
我试图显示列表像...
<section>
<h1>ajo</h1>
<h2>belly acres</h2>
</section>
<section>
<h1>alpine</h1>
<h2>alpine village</h2>
</section>
<section>
<h1>apache junction</h1>
<h2>lost dutchman</h2>
<h2>butterfield</h2>
<h2>benson</h2>
</section>
<section>
<h1>bisbee</h1>
<h2>queen mine</h2>
</section>
我目前使用的代码对于只有一个名称的城市工作正常,但在Apache Junction的示例中有多个名称,我得到这个..
<section>
<h1>apache junction</h1>
</section>
<h2>lost dutchman</h2>
<h2>butterfield</h2>
<h2>benson</h2>
<section>
<h1>bisbee</h1>
<h2>queen mine</h2>
</section>
我想在一节中显示Apache连接点中的所有位置名称。这是我正在使用的代码...
$previousLevel = "";
$city_query = $wpdb->get_results($wpdb->prepare("SELECT name, city FROM locations"));
foreach ($city_query as $city_list) {
$city = $city_list->city;
$name = $city_list->name;
if ($city != $previousLevel) {
$dump_list .= '<section><h1>' . $city . '</h1>';
$dump_list_end = '</section>';
}
$dump_list .= '<h2><a href="#">' . $name . '</a></h2>';
$dump_list .= $dump_list_end;
$previousLevel = $city;
}
任何帮助,将不胜感激。