如何这样布局数据
数据结构如下:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for arp_careset
-- ----------------------------
CREATE TABLE `arp_careset` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set utf8 default NULL,
`typegroup` varchar(255) character set utf8 default NULL,
`remark` varchar(255) character set utf8 default NULL,
`deleted` int(11) default NULL,
`modified_by` int(11) default NULL,
`createtime` datetime default NULL,
`created_by` int(11) default NULL,
`lastmodifytime` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `arp_careset` VALUES ('1', '体表', 'dissect-position', 'surface', '1', null, '0000-00-00 00:00:00', '0', '0000-00-00 00:00:00');
INSERT INTO `arp_careset` VALUES ('2', '淋巴结', 'dissect-position', 'lymph', '1', null, '0000-00-00 00:00:00', '0', '0000-00-00 00:00:00');
INSERT INTO `arp_careset` VALUES ('3', '头颈部', 'dissect-position', 'head', '1', null, '0000-00-00 00:00:00', '0', '0000-00-00 00:00:00');
INSERT INTO `arp_careset` VALUES ('4', '胸部', 'dissect-position', 'chest', '1', null, '0000-00-00 00:00:00', '0', '0000-00-00 00:00:00');
INSERT INTO `arp_careset` VALUES ('5', '腹部', 'dissect-position', 'abdomen', '1', null, '0000-00-00 00:00:00', '0', '0000-00-00 00:00:00');
INSERT INTO `arp_careset` VALUES ('6', '营养状况', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', '0000-00-00 00:00:00');
INSERT INTO `arp_careset` VALUES ('7', '分泌物', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('8', '被毛', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('9', '皮肤', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('10', '眼/眼眶', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('11', '四肢/尾巴', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('12', '乳腺', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('13', '外生殖器', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('14', '肛门', 'position-surface', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('15', '腋窝淋巴结', 'position-lymph', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('16', '颈部淋巴结', 'position-lymph', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('17', '腹股沟淋巴结', 'position-lymph', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('18', '肺部淋巴结', 'position-lymph', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('19', '肠系淋巴结', 'position-lymph', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('20', '眼睑/角膜/瞳孔', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('21', '牙齿/牙龈', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('22', '耳', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('23', '鼻', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('24', '脑膜/全脑', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('25', '颅骨', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('26', '唾液腺', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('27', '食管', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('28', '气管', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('29', '甲状腺', 'position-head', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('30', '胸壁', 'position-chest', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('31', '横膈/纵膈', 'position-chest', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('32', '心脏', 'position-chest', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('33', '主动脉弓', 'position-chest', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('34', '肺及支气管', 'position-chest', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('35', '腹腔', 'position-abdomen', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('36', '肠系膜', 'position-abdomen', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('37', '脾脏', 'position-abdomen', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('38', '胰', 'position-abdomen', '', '1', null, '0000-00-00 00:00:00', '0', null);
INSERT INTO `arp_careset` VALUES ('39', '肾脏', 'position-abdomen', '', '1', null, '0000-00-00 00:00:00', '0', null);
$sql = 'select group_concat(name) as name from arp_careset group by typegroup order by id';
$rs = mysql_query($sql);
while($r = mysql_fetch_assoc($rs)) {
$ar = explode(',', $r['name']);
echo array_shift($ar) . '<br />';
echo '<hr>';
echo join(' ', $ar) . '<br />';
}
$sql1 = "select remark,name from arp_careset where typegroup ='dissect-position' order by id";
$rs1 = mysql_query($sql1);
while($r1 = mysql_fetch_assoc($rs1)) {
echo $r1['name']. '<br />';
$sql = "select group_concat(name) as name from arp_careset where typegroup <>'dissect-position' and typegroup like '%".$r1["remark"]."%' order by id";
$rs = mysql_query($sql);
while($r = mysql_fetch_array($rs)) {
$ar = explode(',', $r['name']);
echo join(' ', $ar) . '<br />';
echo '<hr>';
}
}