0

i want to create a family tree website in which members can be added dynamically through backend. I am usin php-mvc,mysql. I am adding members through backend and I have 4 tables 1. members-details of members and also father,mother ids; 2 partner-to show partner relationships 3 child - to show child relationships 4 sibling - to show sibling relationships

My table structure Members

CREATE TABLE IF NOT EXISTS `members` (
  `members_id` int(10) NOT NULL AUTO_INCREMENT,
  `members_family` int(10) NOT NULL,
  `members_first_name` varchar(500) NOT NULL,
  `members_sur_name` varchar(500) DEFAULT NULL,
  `members_gender` int(10) DEFAULT '0' COMMENT '0-notset,1-male,2-female,3-transgender',
  `members_birth_date` date DEFAULT NULL,
  `members_is_living` int(10) DEFAULT NULL,
  `members_death_date` date NOT NULL DEFAULT '0000-00-00',
  `members_email` varchar(1000) DEFAULT NULL,
  `members_mobile` varchar(500) DEFAULT NULL,
  `members_telephone` varchar(500) DEFAULT NULL,
  `members_website` varchar(1000) DEFAULT NULL,
  `members_blog` varchar(1000) DEFAULT NULL,
  `members_skype` varchar(1000) DEFAULT NULL,
  `members_address` varchar(5000) DEFAULT NULL,
  `members_birth_place` varchar(1000) DEFAULT NULL,
  `members_death_place` varchar(1000) DEFAULT NULL,
  `members_profession` varchar(1000) DEFAULT NULL,
  `members_company` varchar(1000) DEFAULT NULL,
  `members_interests` varchar(5000) DEFAULT NULL,
  `members_notes` varchar(1000) DEFAULT NULL,
  `members_father` varchar(10) DEFAULT NULL,
  `members_mother` int(10) DEFAULT NULL,
  `members_generation` int(10) DEFAULT NULL,
  `members_status` int(10) NOT NULL,
  `members_image` varchar(1000) DEFAULT NULL,
  `members_inserttime` datetime NOT NULL,
  `members_updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`members_id`)
) 

Partner

CREATE TABLE IF NOT EXISTS `partner` (
  `partner_id` int(10) NOT NULL AUTO_INCREMENT,
  `partner_member` int(10) NOT NULL,
  `partner_of_member` int(10) NOT NULL COMMENT 'partner of which member in members_table',
  `partner_relation_status` int(10) NOT NULL COMMENT '1-current,2-ex-partner',
  `partner_status` int(10) NOT NULL,
  `partner_inserttime` datetime NOT NULL,
  `partner_updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`partner_id`)
) 

child

CREATE TABLE IF NOT EXISTS `child` (
  `child_id` int(10) NOT NULL AUTO_INCREMENT,
  `child_member` int(10) NOT NULL,
  `child_of_member` int(10) NOT NULL,
  `child_status` int(10) NOT NULL,
  `child_inserttime` datetime NOT NULL,
  `child_updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`child_id`)
)

sibling

CREATE TABLE IF NOT EXISTS `sibling` (
  `sibling_id` int(10) NOT NULL AUTO_INCREMENT,
  `sibling_member` int(10) NOT NULL,
  `sibling_of_member` int(10) NOT NULL COMMENT 'sibling of which member in mebers table',
  `sibling_relation` int(10) NOT NULL COMMENT '1-younger,2-elder',
  `sibling_status` int(10) NOT NULL,
  `sibling_inserttime` datetime NOT NULL,
  `sibling_updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`sibling_id`)
) 

I am adding values to this table . Now I need to show this as a tree structure. I didnt get any idea from my searchings, Can anyone help me to traverse data as a family tree .

4

1 回答 1

0

我不认为你的表结构是最好的解决方案。您应该创建 1 个表:“Person”并将每个人都放入该表中。您可以在“人员”表中添加一个“角色”字段,以指示该人的“角色”(父亲、母亲、伴侣等)。有关分层数据的更多信息:http: //mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

如果可以查询数据,则只需将其转换为 json 树即可。查看“ jqTree ”以获取有关 json 树结构的更多信息。

于 2016-01-06T13:01:48.570 回答