<?php

require_once '../conexion.php';


$db = new Database();
$con = $db->conectar();

$bd = $_POST['BD'];


$valido = ['data' => [], 'etiquetas' => ''];

//Listamos los reigistros 
$consulta = "SELECT * FROM `$bd` ";
$query = $con->query($consulta);
$query->execute();
$resultados = $query->fetchAll(PDO::FETCH_ASSOC);

//Obtenemos las etiquetas
$consEti = "SELECT column_name
FROM information_schema.columns
WHERE table_name = '$bd' AND TABLE_SCHEMA = 'hamburguesas';
";
$queryEt = $con->query($consEti);
$queryEt->execute();
$resultadosEt = $queryEt->fetchAll(PDO::FETCH_ASSOC);
$values = array();
foreach ($resultadosEt as $item) {
    $values[] = $item['column_name'];
}


$valido['data'] = $resultados;
$valido['etiquetas'] = $values;

echo json_encode($valido);
