我试图用PHP从数据库行(例如这些行)中格式化分层布局,我正忙得不可开交。谁能帮助我,如果国家/地区不同,我尝试使用 foreach 循环并设置一个开关,但我无法让其他人正确格式化。
ID City State Country
==================================================
1 Dallas Texas United States
2 Baltimore Maryland United States
3 Houston Texas United States
4 Essex London United Kingdom
5 Salford Manchester United Kingdom
给我以下内容(最好在多选字段中)
United States
--Maryland
----Baltimore
--Texas
----Dallas
----Houston
United Kingdom
-- London
---- Essex
-- Manchester
----Salford
<select multiple="yes" name="locations">
<option value="United States">United States</option>
<option value="Maryland">-- Maryland</option>
<option value="Baltimore">---- Baltimore</option>
<option value="Texas">-- Texas</option>
<option value="Dallas">---- Dallas</option>
<option value="Houston">---- Houston</option>
<option value="United Kingdom">United Kingdom</option>
<option value="London">-- London</option>
<option value="Essex">---- Essex</option>
<option value="Manchester">-- Manchester</option>
<option value="Salford">---- Salford</option>
</select>