diff --git a/Interfaz/control/inicializar_asientos.php b/Interfaz/control/inicializar_asientos.php new file mode 100644 index 0000000..aa001b3 --- /dev/null +++ b/Interfaz/control/inicializar_asientos.php @@ -0,0 +1,39 @@ +<?php +require 'conexionbd.php'; + +$artistas = ['The Driver Era', 'The 1975', 'Taylor Swift']; +$dias = [22, 23, 24]; +$filas = 10; +$columnas = 12; + +try { + $stmt = $conn->query("SELECT COUNT(*) AS total FROM asientos"); + $resultado = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($resultado['total'] > 0) { + echo "La base de datos ya ha sido inicializada. No se insertaron nuevos asientos."; + exit; + } + + $stmt = $conn->prepare("INSERT INTO asientos (artista, dia, asiento, estado) VALUES (:artista, :dia, :asiento, 'disponible')"); + + foreach ($artistas as $artista) { + foreach ($dias as $dia) { + for ($i = 1; $i <= $filas; $i++) { + for ($j = 0; $j < $columnas; $j++) { + $asiento = $i . chr(65 + $j); + $stmt->execute([ + ':artista' => $artista, + ':dia' => $dia, + ':asiento' => $asiento + ]); + } + } + } + } + + echo "Base de datos inicializada correctamente."; +} catch (PDOException $e) { + die("Error al inicializar la base de datos: " . $e->getMessage()); +} +?>