数据结构如下: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,
  `re` 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);如何让他这样显示:体表
---------------------------------------------------------------------------
营养状况 分泌物 被毛 皮肤 眼/眼眶 四肢/尾巴 乳腺 外生殖器 肛门
---------------------------------------------------------------------------淋巴结
---------------------------------------------------------------------------
腋窝淋巴结 颈部淋巴结 腹股沟淋巴结 肺部淋巴结 肠系淋巴结
---------------------------------------------------------------------------头颈部
---------------------------------------------------------------------------
眼睑/角膜/瞳孔 牙齿/牙龈 耳 鼻 脑膜/全脑 颅骨 唾液腺 食管 气管 甲状腺
---------------------------------------------------------------------------胸部
---------------------------------------------------------------------------
胸壁 横膈/纵膈 心脏 主动脉弓 肺及支气管
---------------------------------------------------------------------------腹部
---------------------------------------------------------------------------
腹腔 肠系膜 脾脏 胰 肾脏
---------------------------------------------------------------------------

解决方案 »

  1.   

    $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 />';
    }
     
      

  2.   


    $sql1 = "select re,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["re"]."%' order by id";
    $rs = mysql_query($sql);
    while($r = mysql_fetch_array($rs)) {
    $ar = explode(',', $r['name']);
    echo join(' ', $ar) . '<br />';
    echo '<hr>';
    }
    }
      

  3.   

    是的,我也看错了
    你是要这样关联 
    typegroup         re
    dissect-position  surface
    position-surface
      

  4.   

    这个问题还是没有彻底解决,需要高手帮忙,问题帖子地址http://bbs.csdn.net/topics/390301872
      

  5.   

    那就这样写$rs = mysql_query("select name, SUBSTRING_INDEX(typegroup,'-',-1) as secondary, re from arp_careset where SUBSTRING_INDEX(typegroup,'-',1)='dissect'");
    while($r = mysql_fetch_assoc($rs)) {
      echo $r['name']. '<br />';
      $rs1 = mysql_query("select name, SUBSTRING_INDEX(typegroup,'-',-1) as secondary, re from arp_careset where SUBSTRING_INDEX(typegroup,'-',1)='$r[secondary]' and SUBSTRING_INDEX(typegroup,'-',-1) = '$r[re]'");
      while($r = mysql_fetch_assoc($rs1)) {
        echo $r['name'] . ' ';
      }
      echo '<br />';
    }体表
    营养状况 分泌物 被毛 皮肤 眼/眼眶 四肢/尾巴 乳腺 外生殖器 肛门 
    淋巴结
    腋窝淋巴结 颈部淋巴结 腹股沟淋巴结 肺部淋巴结 肠系淋巴结 
    头颈部
    眼睑/角膜/瞳孔 牙齿/牙龈 耳 鼻 脑膜/全脑 颅骨 唾液腺 食管 气管 甲状腺 
    胸部
    胸壁 横膈/纵膈 心脏 主动脉弓 肺及支气管 
    腹部
    腹腔 肠系膜 脾脏 胰 肾脏