我正在显示mysql的列表。 (http://www.jetcleandrives.co.uk/Areas_Covered.php)
这是代码,
if ($rows['area_shire'] != $area_shire && isset ($rows['area_shire'])){
$area_shire = $rows['area_shire'];
$area_shire_url = str_replace(' ', '_', $area_shire);
echo '<div class="area_name"><h2><a href=Driveway_Cleaning_'.$area_shire_url.'>'.$area_shire.'</a></h2></div><br>';
}
echo '<div class "areas_column">';
if ($rows['area_district'] != $area_district && isset ($rows['area_district'])){
$area_district = $rows['area_district'];
$area_district_url = str_replace(' ', '_', $area_district);
echo '<div class="area_name"><h3><a href=Driveway_Cleaning_'.$area_district_url.'>'.$area_district.'</a></h3></div><br>';
}
if ($rows['area_name'] != $area_name && isset ($rows['area_name'])){
$area_name = $rows['area_name'];
$area_name_url = str_replace(' ', '_', $area_name);
echo '<div class="area_name"><a href=Driveway_Cleaning_'.$area_name_url.'>'.$area_name.'</a></div><br>';
但是我不希望它成为一个长的Verticle列表。我希望每个区域,例如Birmingham,Sandwell等,使用divs和float开始一个新的“列”:left但是我无法找到从哪里开始并关闭div。有人可以帮忙吗?
答案 0 :(得分:0)
尝试这样的事情:
$area_district = null; // set this to null initially, so you can identify the first iteration
if ($rows['area_shire'] != $area_shire && isset ($rows['area_shire'])){
$area_shire = $rows['area_shire'];
$area_shire_url = str_replace(' ', '_', $area_shire);
echo '<div class="area_name"><h2><a href=Driveway_Cleaning_'.$area_shire_url.'>'.$area_shire.'</a></h2></div><br>';
}
if ($rows['area_district'] != $area_district && isset ($rows['area_district'])){
if($area_district!==null) echo '</div>'; // only close the previous div if this isn't the first
echo '<div class "areas_column">'; // open the div only when the district changes
$area_district = $rows['area_district'];
$area_district_url = str_replace(' ', '_', $area_district);
echo '<div class="area_name"><h3><a href=Driveway_Cleaning_'.$area_district_url.'>'.$area_district.'</a></h3></div><br>';
}
if ($rows['area_name'] != $area_name && isset ($rows['area_name'])){
$area_name = $rows['area_name'];
$area_name_url = str_replace(' ', '_', $area_name);
echo '<div class="area_name"><a href=Driveway_Cleaning_'.$area_name_url.'>'.$area_name.'</a></div><br>';
}
echo '</div>'; // close the last div