function getTree($dataset) {
$tree = array();
foreach ($dataset as $id => &$node) {
//Если нет вложений
if (!$node->parent_id){
$tree[$id] = &$node;
}else{
//Если есть потомки то переберем массив
$dataset[$node->parent_id]->childs[$id] = &$node;
}
}
return $tree;
}
$link = mysqli_connect('localhost', '', '',
'test') or die('Could not connect: '.mysqli_error());
$query = "SELECT * FROM `categories`";
$query1 = "SELECT * FROM `locations` l INNER JOIN `categories` c ON c.category_key=l.key_i WHERE 1";
$query2 = "SELECT * FROM `levels`";
$result = mysqli_query($link, $query) or die('Query failed: '.mysqli_error());
$result1 = mysqli_query($link, $query1) or die('Query failed: '.mysqli_error());
$result2 = mysqli_query($link, $query2) or die('Query failed: '.mysqli_error());
$response = [
'mapwidth' => 1000,
'mapheight' => 600,
'categories' => [],
'levels' => [],
];
while ($category = mysqli_fetch_object($result)) {
$response['categories'][] = [
'title' => $category->title_c,
];
}
while ($level = mysqli_fetch_object($result2)) {
$response['levels'][$level->levels_key] = [
'title' => $level->title_i,
'map' => $level->map_i,
];
}
var_dump($result1);
while ($location = mysqli_fetch_object($result1)) {
echo $location->key_i;
$response['levels'][$location->key_i]['locations'][] = [
'title' => $location->title_l,
'about' => $location->about_l,
'category' => $location->title_c,
];
}
file_put_contents("chart_data.json", json_encode($response, JSON_UNESCAPED_UNICODE));
echo json_encode($response, JSON_PRETTY_PRINT);
.parent{
position: relative;
}
.star {
position: absolute;
top: 10px;
left: 10px;
font-size: 13px;
color: #fff;
}
echo $xml_result_adeo['detail']['caption'];
var json = [{'id':1, 'name':'John', 'collection':'boston'},
{'id':2, 'name':'Faer', 'collection':'antler'},
{'id':3, 'name':'klei', 'collection':'aqua'},
{'id':4, 'name':'Inda', 'collection':'boston'},
{'id':5, 'name':'Faer', 'collection':'antler'}];
var result = new Set();
for (var i = 0; i < json.length; i++) {
result.add(json[i].collection);
}
console.log(result);