<?php
include 'conexao.php';

$categoria_id = $_GET['categoria_id'];
$result = $conn->query("SELECT id, codigo, nome FROM subcategorias_financeiras WHERE categoria_id = $categoria_id ORDER BY codigo");

$subcategorias = [];
while ($row = $result->fetch_assoc()) {
    $subcategorias[] = [
        'id' => $row['id'],
        'nome' => $row['codigo'] . ' - ' . $row['nome']
    ];
}

header('Content-Type: application/json');
echo json_encode($subcategorias);
