
03/01/2015, 08:02
|
|
Respuesta: ¿Cómo se puede hacer en PHP? Muchas gracias!! Cita:
Iniciado por gnzsoloyo Hay muchísimos ejemplos de cómo recorrer un resultado de una consulta y mostrarlo en forma de tabla. Es raro que no hayas usado alguno.
Este es uno, encontrado aquí:
Código PHP:
Ver original<?php require_once 'Connection.simple.php'; $result; $conn = dbConnect(); // Create the query $sql = 'SELECT * FROM empleado'; // Create the query and asign the result to a variable call $result $result = $conn->query($sql); // Extract the values from $result $rows = $result->fetchAll(); // Since the values are an associative array we use foreach to extract the values from $rows ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Query data sending an ID</title> <meta http-equiv="X-UA-Compatible" content="IE=9,crome" /> <meta name="copyright" content="Datasoft Engineering 2013"/> <meta name="author" content="Reedyseth"/> <meta name="description" content="Query data sending an ID" /> <link rel=stylesheet href="../css/style01.css"> </head> <body> <table border="1"> <thead> <tr> <th>ID</th> <th>Nombre</th> <th>Email</th> <th>Telefono</th> </tr> </thead> <tbody> <?php foreach ($rows as $row) { ?> <tr> <td><a href="searchEmployee.php?id=<?php echo $row['id_empleado']; ?>"><?php echo $row['id_empleado']; ?></a></td> <td><?php echo $row['nombre']; ?></td> <td><?php echo $row['email']; ?></td> <td><?php echo $row['telefono']; ?></td> </tr> <?php } ?> </tbody> </table> </html>
A partir de la línea 27 podrás ver cómo construye la tabla en la vista, y cómo recorre el array obtenido para poner los datos.
Mi único consejo es que uses alias en la salida de la consulta cuando uses funcioens de agregación, para simplificar el identificador de columnas: Así, en lugar de llamarla por "COUNT(idusuarios)", la invocas por "TotalIds". |