<?php
function getChildren($m_id, $m_name) {
global $db, $tbl_main;
$SQL =
"SELECT m_id, m_name, m_parent_id FROM $tbl_main
WHERE m_parent_id = $m_id ORDER BY m_sort";
$query = $db->query($SQL);
// получим массив, в котором будет дерево элементов в иерархическом порядке
$tree = [
'id' => $m_id,
'name' => $m_name,
'children' => [],
];
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$tree['children'][] = getChildren($row['m_id'], $row['m_name']);
}
return $tree;
}
print '<pre>';
print_r(getChildren($root_id, $root_name));
print '</pre>';
curl -sL https://deb.nodesource.com/setup | sudo bash -
вставить для установки репозиториевsudo apt-get update && sudo apt-get install -y nodejs
установить нодуsudo vim /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_0.10 ....
deb-src https://deb.nodesource.com/node_0.10 ...
deb https://deb.nodesource.com/node_0.12 ....
deb-src https://deb.nodesource.com/node_0.12 ...
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y nodejs
which node; man node
function GetChildren($m_id){
global $db, $tbl_main;
$SQL="SELECT m_id, m_name, m_parent_id
FROM $tbl_main
WHERE m_parent_id=$m_id
ORDER BY m_sort";
$query=$db->Execute($SQL);
while ($array = $query->FetchRow()) {
$children[] = array('id' => $array['m_id'], 'name' => $array['m_name']);
}
if ($children){
foreach ($children as $value){
$aux[] = GetChildren($value['id']);
}
}
return $aux[];
}
print '<pre>';
// print_r(GetChildren($root_id));
print '</pre>';