function remove_sub_nav_items($id, $connection)
{
    $sub_nav_stmt = get_sub_nav_items($connection);
    if ($sub_results = $sub_nav_stmt->get_result()) {
        while ($sub_row = $sub_results->fetch_assoc()) {
            remove_link_item($sub_row['id'], true, $connection);
            remove_section_item($sub_row['id'], true, $connection);
            remove_sub_nav_item($sub_row['id'], $connection);
        }
        $sub_results->close();
    }
}
function get_nav_items($connection)
{
    $connection->begin_transaction();
    $get_nav_query = <<<SQL
select ni.id, ni.type, ni.text, nitl.url, nits.section_id
from nav_item ni
left join nav_item_to_section nits on nits.nav_item_id = ni.id and nits.nav_item_type = 'NAV_ITEM'
left join nav_item_to_link nitl on nitl.nav_item_id = ni.id and nitl.nav_item_type = 'NAV_ITEM'
order by ni.order asc;
SQL;
    if ($results = $connection->query($get_nav_query)) {
        $result_array = [];
        while ($row = $results->fetch_assoc()) {
            $sub_nav_item_array = [];
            $nav_item_array = get_array_from_row($row);
            if ($row['type'] == "DROPDOWN") {
                $get_sub_nav_stmt = get_sub_nav_items($connection);
                $get_sub_nav_stmt->bind_param("i", $row['id']);
                catch_execution_error($get_sub_nav_stmt->execute(), $connection);
                $sub_results = $get_sub_nav_stmt->get_result();
                while ($sub_row = $sub_results->fetch_assoc()) {
                    $sub_nav_item_array[] = get_array_from_row($sub_row);
                }
                $sub_results->close();
            }
            $nav_item_array['subNavItems'] = $sub_nav_item_array;
            $result_array[] = $nav_item_array;
        }
        print "[[\"SUCCESS\"],";
        print json_encode($result_array);
        print "]";
        $results->close();
    } else {
        $error = $connection->error;
        print "[[\"ERROR\"],[\"{$error}\"]]";
        exit;
    }
    $connection->commit();
}