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);
SELECT o.order_id, и другие колонки, op.product_id, op.order_id, p.id, p.name
FROM orders as o
LEFT JOIN order_product as op ON o.order_id = op.order_id
LEFT JOIN products as p ON op.product_id = p.id