<?php
require_once 'init.php';
if (!$link) {
$error = mysqli_connect_error();
$content = include_template('error.php', ['error' => $error]);
}
else {
$sql = 'SELECT * FROM categories WHERE `ref_id` IS NULL';
$result = mysqli_query($link, $sql);
if ($result) {
$categories = mysqli_fetch_all($result, MYSQLI_ASSOC);
$sql = 'SELECT * FROM categories WHERE `ref_id` IS NOT NULL';
$result = mysqli_query($link, $sql);
if($result) {
$subcategories = mysqli_fetch_all($result, MYSQLI_ASSOC);
$content = include_template('main.php', ['categories' => $categories, 'subcategories' => $subcategories]);
}
else {
$error = mysqli_error($link);
$content = include_template('error.php', ['error' => $error]);
}
}
else {
$error = mysqli_error($link);
$content = include_template('error.php', ['error' => $error]);
}
}
print(include_template('layout.php', ['content' => $content]));