<?php
require_once 'db.php';

function get_adm_units($mysqli) {
    $units = [];
    $sql = "SELECT id, wadmkk FROM adm_unit ORDER BY wadmkk";
    if ($res = $mysqli->query($sql)) {
        while ($row = $res->fetch_assoc()) $units[] = $row;
        $res->free();
    }
    return $units;
}

function get_distinct_kkop($mysqli) {
    $vals = [];
    $sql = "SELECT DISTINCT JSON_UNQUOTE(JSON_EXTRACT(attributes,'$.kkop_1')) AS kkop FROM rtrw_object WHERE attributes IS NOT NULL AND JSON_EXTRACT(attributes,'$.kkop_1') IS NOT NULL ORDER BY kkop";
    if ($res = $mysqli->query($sql)) {
        while ($row = $res->fetch_assoc()) {
            if ($row['kkop'] !== null && $row['kkop'] !== '') $vals[] = $row['kkop'];
        }
        $res->free();
    }
    return $vals;
}
?>