-
-
Save parzibyte/a0fed27c00bbc4b16ec57c8aced3b1f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
CRUD con SQL Server y PHP | |
@author parzibyte [parzibyte.me/blog] | |
@date 2019-06-03 | |
================================ | |
Este archivo lista todos los | |
datos de la tabla, obteniendo a | |
los mismos como un arreglo | |
================================ | |
*/ | |
?> | |
<?php | |
include_once "base_de_datos.php"; | |
$sentencia = $base_de_datos->query("select id, nombre, edad from mascotas"); | |
$mascotas = $sentencia->fetchAll(PDO::FETCH_OBJ); | |
?> | |
<!--Recordemos que podemos intercambiar HTML y PHP como queramos--> | |
<?php include_once "encabezado.php" ?> | |
<div class="row"> | |
<!-- Aquí pon las col-x necesarias, comienza tu contenido, etcétera --> | |
<div class="col-12"> | |
<h1>Listar con arreglo</h1> | |
<a href="//parzibyte.me/blog" target="_blank">By Parzibyte</a> | |
<br> | |
<div class="table-responsive"> | |
<table class="table table-bordered"> | |
<thead class="thead-dark"> | |
<tr> | |
<th>ID</th> | |
<th>Nombre</th> | |
<th>Edad</th> | |
<th>Editar</th> | |
<th>Eliminar</th> | |
</tr> | |
</thead> | |
<tbody> | |
<!-- | |
Atención aquí, sólo esto cambiará | |
Pd: no ignores las llaves de inicio y cierre {} | |
--> | |
<?php foreach($mascotas as $mascota){ ?> | |
<tr> | |
<td><?php echo $mascota->id ?></td> | |
<td><?php echo $mascota->nombre ?></td> | |
<td><?php echo $mascota->edad ?></td> | |
<td><a class="btn btn-warning" href="<?php echo "editar.php?id=" . $mascota->id?>">Editar 📝</a></td> | |
<td><a class="btn btn-danger" href="<?php echo "eliminar.php?id=" . $mascota->id?>">Eliminar 🗑️</a></td> | |
</tr> | |
<?php } ?> | |
</tbody> | |
</table> | |
</div> | |
</div> | |
</div> | |
<?php include_once "pie.php" ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment