代码拉取完成,页面将自动刷新
同步操作将从 jiehu0992/家谱familytree 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
// Database connection using mysqli
$mysqli = new mysqli("127.0.0.1","root","root", "Database");
if ($mysqli->connect_errno) {
die("Failed to connect to MySQL: " . $mysqli->connect_error);
}
// Prepare statement
$sql = "SELECT * FROM tree_lr";
$stmt = $mysqli->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
// Fetch results into an array
$array = array();
while ($row = $result->fetch_assoc()) {
$array[] = $row;
}
// Optimize the lefttree() function
function lefttree($array){
$tree = array();
$categorylist = "";
foreach ($array as $v) {
$list = @$tree[$v['pid']] ?: array();
$list[] = $v;
$tree[$v['pid']] = $list;
}
if (is_array($tree[0])) {
$categorylist = "<ul>\n";
$categorylist .= sonTree($tree[0], $tree);
$categorylist .= "</ul>\n";
}
return $categorylist;
}
function sonTree($arr, $tree, $level = 1) {
$categorylist = "";
foreach ($arr as $k => $v) {
if ($tree[$v['id']]) {
$categorylist .= "<li><a href=\"#\" style='color: ";
$categorylist .= ($v['sex'] == '女') ? '#ff1493' : 'black';
$categorylist .= ";'>{$v['name']}</a>\n";
$categorylist .= "<ul>\n";
$categorylist .= sonTree($tree[$v['id']], $tree, $level + 1);
$categorylist .= "</ul>\n";
$categorylist .= "</li>\n";
} else {
if ($v['is_link'] == 0) {
$categorylist .= "<li><a href=\"#\" style='color: ";
$categorylist .= ($v['sex'] == '女') ? '#ff1493' : 'black';
$categorylist .= ";'>{$v['name']}</a></li>\n";
}
}
}
return $categorylist;
}
// Generate the menu
$menu = lefttree($array);
if ($link && mysqli_ping($link)) {
mysqli_close($link);
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。