显示图例:
数据库结构:
CREATE TABLE `successuser` (
`id` int(6) unsigned NOT NULL auto_increment,
`big` varchar(50) default NULL,
`bigaddress` varchar(50) default NULL,
`saddress` varchar(50) default NULL,
`content` varchar(50) default NULL,
`time` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=409 ;
//临时数据
INSERT INTO `successuser` VALUES (9, '湖南', '岳阳地区', '岳阳市', '岳阳市民院附小 ', '2008-06-30 14:40:32');
INSERT INTO `successuser` VALUES (10, '湖南', '岳阳地区', '岳阳市', '岳阳市云溪乡中心小学', '2008-06-30 14:40:51');
INSERT INTO `successuser` VALUES (156, '湖南', '长沙地区', '芙蓉区', '长沙市芙蓉区第一幼儿园', '2008-06-30 15:44:23');
INSERT INTO `successuser` VALUES (157, '湖南', '长沙地区', '雨花区', '中南林业调查规划设计院', '2008-06-30 15:44:52');
INSERT INTO `successuser` VALUES (237, '湖南', '长沙地区', '浏阳市', '浏阳市永安镇中心完小', '2008-06-30 16:09:46');
INSERT INTO `successuser` VALUES (238, '湖南', '益阳市', '益阳市', '益阳市第十六中学 ', '2008-06-30 16:10:14');
INSERT INTO `successuser` VALUES (259, '湖南', '张家界地区', '桑植县', '桑植县洪家关小学', '2008-06-30 16:17:35');
INSERT INTO `successuser` VALUES (260, '湖南', '怀化地区', '芷江县', '芷江县教育局 ', '2008-06-30 16:18:48');
INSERT INTO `successuser` VALUES (405, '其它用户', '', '', '云溪区教育局', '2008-06-30 17:18:23');
INSERT INTO `successuser` VALUES (407, '湖南', '常德地区', '津市', '津市中学', '2008-10-20 9:48:21');
INSERT INTO `successuser` VALUES (408, '湖南', '永州地区', '道县', '道县一中', '2008-11-01 6:53:23');
实现方法
<style>
td {
text-align:left;
font-size: 12px;
line-height: 20px;
}
.style1 {
background-color: #D4AC89;
margin-right:1px;
color:#FFFFFF;
font-weight: bold;
}
.style2 {
color: #676767;
}
</style>
<?php
//连接并选择到数据库服务器
$connection = mysql_connect ($db_host, $db_username, $db_userpass);
mysql_select_db($db_database, $connection);
//查询数据
mysql_query("SET NAMES 'gbk'");
$query="SELECT distinct bigaddress FROM successuser where big='湖南' group by bigaddress";
$result=mysql_query($query,$connection);
//mysql_fetch_array()获得数据,并输出
?>
<table cellpadding="0" lign="left" cellspacing="0">
<?
while($rowa=mysql_fetch_array($result)){
$row[]=$rowa;
}
for ($jj=0;$jj<=count($row);$jj++){ //数据组ID走动
?>
<tr>
<?
for ($j=$jj;$j<=$jj+8;$j++){ //实际ID
?>
<td width="100" valign="top"><div class="style1"><?=$row[$j][0]?></div>
<?
$query1="SELECT distinct saddress FROM successuser where big='湖南' and bigaddress='".$row[$j][0]."'";
$i=0;
$result1=mysql_query($query1,$connection);
while($row1=mysql_fetch_array($result1))
{
?>
<div class="style2" style="background-color:
<? if ($i==1) {$i--;echo "#F3F3F3";} else {$i++;} ?>">
<a href="<?=Pinyin($row1[0]).'.html'?>"><?=$row1[0]?></a></div>
<? }?>
</td>
<?
}
$jj=$jj+8; //ID补位
?>
</tr>
<? }?>
</table>