我有一个 MySQL 数据库
id area_name area_district area_shire
1 Harborne Birmingham West Midlands
2 Edgbaston Birmingham West Midlands
3 Halesowen Dudley West Midlands
4 Rugby Warwickshire
5 Nuneaton Warwickshire
我如何让这个显示,
West Midlands (main heading)
Birmingham (sub heading)
Harborne
Edgbaston
Dudley (sub heading)
Halesowen
Warwickshire (main heading)
Rugby
Nuneaton
是否有一个while循环可以实现这一点?
编辑:这是我迄今为止尝试过的:
$query = mysql_query("SELECT * FROM Areas_Covered ORDER BY ID"); //fetch the results
// convert results into an array
while($rows = mysql_fetch_array($query)):
$area_name = $rows ['area_name'];
$area_district = $rows ['area_district'];
$area_name_url = str_replace(' ', '_', $area_name);
echo "<a href=\"Driveway_Cleaning_$area_name_url.php\">$area_name</a><br>";
endwhile;