代码拉取完成,页面将自动刷新
同步操作将从 jiehu0992/家谱familytree 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!DOCTYPE html>
<html>
<head>
<title>族谱增删改查</title>
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<style type="text/css">
@charset "utf-8";
/* It's supposed to look like a tree diagram */
.tree, .tree ul, .tree li {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
.tree {
margin: 0 0 1em;
text-align: center;
}
.tree, .tree ul {
display: table;
}
.tree ul {
width: 100%;
}
.tree li {
display: table-cell;
padding: .5em 0;
vertical-align: top;
}
/* _________ */
.tree li:before {
outline: solid 1px #666;
content: "";
left: 0;
position: absolute;
right: 0;
top: 0;
}
.tree li:first-child:before {left: 50%;}
.tree li:last-child:before {right: 50%;}
.tree code, .tree span {
display: inline-block;
margin: 0 .2em .5em;
padding: .2em .5em;
position: relative;
writing-mode: vertical-rl;
text-orientation: mixed;
white-space: nowrap;
}
/* If the tree represents DOM structure */
.tree code {
font-family: monaco, Consolas, 'Lucida Console', monospace;
}
/* | */
.tree ul:before,
.tree code:before,
.tree span:before {
outline: solid 1px #666;
content: "";
height: .5em;
left: 50%;
position: absolute;
}
.tree ul:before {
top: -.5em;
}
.tree code:before,
.tree span:before {
top: -.5em;
}
/* The root node doesn't connect upwards */
.tree > li {margin-top: 0;}
.tree > li:before,
.tree > li:after,
.tree > li > code:before,
.tree > li > span:before {
outline: none;
}
</style>
<body>
<?php
// 连接数据库
$link = mysqli_connect("127.0.0.1", "lszp", "lszp321", "lszp");
// 查询所有节点
$query = "SELECT id, name, pid,sex, L, R FROM tree_lr ORDER BY L ASC";
$result = mysqli_query($link, $query);
// 构建节点数组
$nodes = array();
while ($row = mysqli_fetch_assoc($result)) {
$nodes[] = $row;
}
// 构建树状结构
$tree = array();
foreach ($nodes as $node) {
$pid = $node['pid'];
if (!isset($tree[$pid])) {
$tree[$pid] = array();
}
$tree[$pid][] = $node;
}
// 递归构建树
function buildTree($tree, $parent_id, &$output) {
if (isset($tree[$parent_id])) {
$output .= "<ul>";
$nodes = $tree[$parent_id];
usort($nodes, function($a, $b) {
return $a['id'] > $b['id'];
});
foreach ($nodes as $node) {
$output .= "<li>";
$color = ($node['sex'] == '女') ? 'ff1493' : '';
$output .= "<span style='color: #$color'>" . $node['name'] . "</span>";
buildTree($tree, $node['id'], $output);
$output .= "</li>";
}
$output .= "</ul>";
}
}
// 生成树形结构
$output = "";
buildTree($tree, 0, $output);
// 输出树形结构
echo "<div class='tree'>" . $output . "</div>";
?>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。