Creacion y Completar BD jugadores

parent 69c0e757
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
include("../config/bd.php"); include("../config/bd.php");
echo($idpartido);
$jornada=(isset($_POST['jornada']))?$_POST['jornada']:""; $jornada=(isset($_POST['jornada']))?$_POST['jornada']:"";
//SELECT id_equipoL, id_equipoV FROM jornadas WHERE id_jornada=:id_jornada //SELECT id_equipoL, id_equipoV FROM jornadas WHERE id_jornada=:id_jornada
...@@ -46,7 +44,7 @@ ...@@ -46,7 +44,7 @@
header("Location:goles.php"); header("Location:goles.php");
break; break;
case "Seleccionar": case "Seleccionar":
$SQL=$conexion->prepare("SELECT * FROM jornadas WHERE id_partido=:id_partido"); $SQL=$conexion->prepare("SELECT id_equipoL, id_equipoV, golesL, golesV FROM jornadas WHERE id_partido=:id_partido");
$SQL->bindParam(':id_partido',$idpartido); $SQL->bindParam(':id_partido',$idpartido);
$SQL->execute(); $SQL->execute();
$partido=$SQL->fetch(PDO::FETCH_LAZY); $partido=$SQL->fetch(PDO::FETCH_LAZY);
...@@ -147,7 +145,9 @@ ...@@ -147,7 +145,9 @@
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>ID Equipo L</th>
<th>Equipo L</th> <th>Equipo L</th>
<th>ID Equipo V</th>
<th>Equipo V</th> <th>Equipo V</th>
<th>Acciones</th> <th>Acciones</th>
</tr> </tr>
...@@ -155,6 +155,9 @@ ...@@ -155,6 +155,9 @@
<tbody> <tbody>
<?php foreach($listapartidos as $partido) {?> <?php foreach($listapartidos as $partido) {?>
<tr> <tr>
<td>
<?php echo $partido['id_equipoL']?>
</td>
<td><?php $SQL2=$conexion->prepare("SELECT Nombre FROM equipos WHERE id = :id_equipoL "); <td><?php $SQL2=$conexion->prepare("SELECT Nombre FROM equipos WHERE id = :id_equipoL ");
$SQL2->bindParam(':id_equipoL',$partido['id_equipoL']); $SQL2->bindParam(':id_equipoL',$partido['id_equipoL']);
$SQL2->execute(); $SQL2->execute();
...@@ -164,6 +167,9 @@ ...@@ -164,6 +167,9 @@
<?php echo $Local['Nombre'] ?> <?php echo $Local['Nombre'] ?>
<?php }?> <?php }?>
</td> </td>
<td>
<?php echo $partido['id_equipoV']?>
</td>
<td><?php $SQL3=$conexion->prepare("SELECT Nombre FROM equipos WHERE id = :id_equipoV "); <td><?php $SQL3=$conexion->prepare("SELECT Nombre FROM equipos WHERE id = :id_equipoV ");
$SQL3->bindParam(':id_equipoV',$partido['id_equipoV']); $SQL3->bindParam(':id_equipoV',$partido['id_equipoV']);
$SQL3->execute(); $SQL3->execute();
......
<?php include("../template/cabecera.php");?> <?php include("../template/cabecera.php");?>
<?php <?php
$txtequipo=(isset($_POST['equipo']))?$_POST['equipo']:""; $idequipo=(isset($_POST['id_equipo']))?$_POST['id_equipo']:"";
$idjugador=(isset($_POST['id_jugador']))?$_POST['id_jugador']:"";
$txtnombreJugador=(isset($_POST['nombreJugador']))?$_POST['nombreJugador']:""; $txtnombreJugador=(isset($_POST['nombreJugador']))?$_POST['nombreJugador']:"";
$accion=(isset($_POST['accion']))?$_POST['accion']:""; $accion=(isset($_POST['accion']))?$_POST['accion']:"";
include("../config/bd.php"); include("../config/bd.php");
switch($accion){ switch($accion){
case "Agregar": case "Agregar":
//INSERT INTO `jugadores` (`id_jugador`, `Nombre`, `id_equipo`) VALUES (NULL, 'Karim Benzema', '16');
$SQL=$conexion->prepare("INSERT INTO jugadores ( Nombre, id_equipo) VALUES (:nombreJugador, :id_equipo);");
$SQL->bindParam(':nombreJugador',$txtnombreJugador);
$SQL->bindParam(':id_equipo',$idequipo);
$SQL->execute();
break; break;
case "Modificar": case "Modificar":
$SQL=$conexion->prepare("UPDATE jugadores SET Nombre=:nombreJugador, id_equipo=:id_equipo WHERE id_jugador=:id_jugador");
$SQL->bindParam(':id_jugador',$idjugador);
$SQL->bindParam(':nombreJugador',$txtnombreJugador);
$SQL->bindParam(':id_equipo',$idequipo);
$SQL->execute();
break; break;
case "Cancelar": case "Cancelar":
break; break;
case "Seleccionar":
$SQL=$conexion->prepare("SELECT * FROM jugadores WHERE id_jugador=:id_jugador");
$SQL->bindParam(':id_jugador',$idjugador);
$SQL->execute();
$jugador=$SQL->fetch(PDO::FETCH_LAZY);
$idjugador=$jugador['id_jugador'];
$txtnombreJugador=$jugador['Nombre'];
$idequipo=$jugador['id_equipo'];
break;
case "Borrar":
$SQL=$conexion->prepare("DELETE FROM jugadores WHERE id_jugador=:id_jugador");
$SQL->bindParam(':id_jugador',$idjugador);
$SQL->execute();
break;
} }
$SQL=$conexion->prepare("SELECT * FROM jugadores");
$SQL=$conexion->prepare("SELECT * FROM equipos");
$SQL->execute(); $SQL->execute();
$listaEquipos=$SQL->fetchAll(PDO::FETCH_ASSOC); $listajugadores=$SQL->fetchAll(PDO::FETCH_ASSOC);
$SQL2=$conexion->prepare("SELECT * FROM equipos");
$SQL2->execute();
$listaEquipos=$SQL2->fetchAll(PDO::FETCH_ASSOC);
?> ?>
<div class="col-md-5"> <div class="col-md-6">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
...@@ -33,65 +60,79 @@ ...@@ -33,65 +60,79 @@
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data">
<div class = "form-group"> <div class = "form-group">
<label for="equipo">ID Jugador: </label>
<input type="text" required readonly class="form-control" value="<?php echo $idjugador;?>" name="id_jugador" id="id_jugador" placeholder="ID del nuevo jugador">
</div>
<div class = "form-group">
<label for="equipo">ID Equipo: </label> <label for="equipo">ID Equipo: </label>
<input type="text" class="form-control" name="equipo" id="equipo" placeholder="Indica el ID del equipo del nuevo jugador"> <input type="number" required min="1" max="20" class="form-control" value="<?php echo $idequipo; ?>" name="id_equipo" id="id_equipo" placeholder="Indica el ID del equipo del nuevo jugador">
</div> </div>
<div class = "form-group"> <div class = "form-group">
<label for="nombreJugador">Nombre: </label> <label for="nombreJugador">Nombre: </label>
<input type="text" class="form-control" name="nombreJugador" id="nombreJugador" placeholder="Añade un jugador"> <input type="text" required class="form-control" name="nombreJugador" value="<?php echo $txtnombreJugador; ?>" id="nombreJugador" placeholder="Añade un jugador">
</div> </div>
<div class="btn-group" role="group" aria-label=""> <div class="btn-group" role="group" aria-label="">
<button type="button" name="accion" value="Agregar" class="btn btn-success">Agregar</button> <button type="submit" name="accion" <?php echo ($accion=="Seleccionar")?"disabled":"";?> value="Agregar" class="btn btn-success">Agregar</button>
<button type="button" name="accion" value="Modificar" class="btn btn-warning">Modificar</button> <button type="submit" name="accion" <?php echo ($accion!="Seleccionar")?"disabled":"";?> value="Modificar" class="btn btn-warning">Modificar</button>
<button type="button" name="accion" value="Cancelar" class="btn btn-info">Cancelar</button> <button type="submit" name="accion" <?php echo ($accion!="Seleccionar")?"disabled":"";?> value="Cancelar" class="btn btn-info">Cancelar</button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-7">
<div class="col-md-6">
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>ID Equipo</th>
<th>Equipo</th> <th>Equipo</th>
<th>Jugador</th>
<th>Tarjetas</th>
<th>Goles</th>
<th>Acciones</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach($listaEquipos as $equipo) {?>
<tr> <tr>
<td>Nombre equipo</td> <td><?php echo $equipo['id'] ?></td>
<td>Nombre jugador</td> <td><?php echo $equipo['Nombre'] ?></td>
<td>Goles</td>
<td>Tarjetas</td>
<td>Seleccionar | Borrar</td>
</tr> </tr>
<?php }?>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="col-md-4"> <div class="col-md-12">
</br>
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>ID Equipo</th>
<th>Equipo</th> <th>Equipo</th>
<th>Jugador</th>
<th>Acciones</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach($listaEquipos as $equipo) {?> <?php foreach($listajugadores as $jugadores) {?>
<tr> <tr>
<td><?php echo $equipo['id'] ?></td> <td><?php $SQL2=$conexion->prepare("SELECT Nombre FROM equipos WHERE id = :id_equipo ");
<td><?php echo $equipo['Nombre'] ?></td> $SQL2->bindParam(':id_equipo',$jugadores['id_equipo']);
$SQL2->execute();
$listaLocales=$SQL2->fetchAll(PDO::FETCH_ASSOC);
?>
<?php foreach($listaLocales as $Local) {?>
<?php echo $Local['Nombre'] ?>
<?php }?>
</td>
<td><?php echo $jugadores['Nombre'] ?></td>
<td>
<form method="POST">
<input type="hidden" name="id_jugador" id="id_jugador" value="<?php echo $jugadores['id_jugador'] ?>"/>
<input type="submit" name="accion" value="Seleccionar" class="btn btn-primary"/>
<input type="submit" name="accion" value="Borrar" class="btn btn-danger"/>
</form>
</td>
</tr> </tr>
<?php }?> <?php }?>
</tbody> </tbody>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment