我的數據庫看起來像這樣...顯示城市和地點的名稱的列表,這些城市
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;
}
任何幫助,將不勝感激。