Ver Mensaje Individual
  #5 (permalink)  
Antiguo 03/01/2015, 08:02
Musiker
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: ¿Cómo se puede hacer en PHP?

Muchas gracias!!

Cita:
Iniciado por gnzsoloyo Ver Mensaje
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
  1. <?php
  2.     require_once 'Connection.simple.php';
  3.     $result;
  4.  
  5.     $conn = dbConnect();
  6.     // Create the query
  7.     $sql = 'SELECT * FROM empleado';
  8.     // Create the query and asign the result to a variable call $result
  9.     $result = $conn->query($sql);
  10.     // Extract the values from $result
  11.     $rows = $result->fetchAll();
  12.     // Since the values are an associative array we use foreach to extract the values from $rows
  13.  ?>
  14.  <!DOCTYPE html>
  15. <html lang="en">
  16.     <head>
  17.         <meta charset="UTF-8" />
  18.         <title>Query data sending an ID</title>
  19.         <meta http-equiv="X-UA-Compatible" content="IE=9,crome" />
  20.         <meta name="copyright" content="Datasoft Engineering 2013"/>
  21.         <meta name="author" content="Reedyseth"/>
  22.         <meta name="email" content="[email protected]"/>
  23.         <meta name="description" content="Query data sending an ID" />
  24.         <link rel=stylesheet href="../css/style01.css">
  25.     </head>
  26.     <body>
  27.         <table border="1">
  28.         <thead>
  29.             <tr>
  30.                 <th>ID</th>
  31.                 <th>Nombre</th>
  32.                 <th>Email</th>
  33.                 <th>Telefono</th>
  34.             </tr>
  35.         </thead>
  36.         <tbody>
  37.         <?php
  38.             foreach ($rows as $row) {
  39.         ?>
  40.             <tr>
  41.                 <td><a href="searchEmployee.php?id=<?php echo $row['id_empleado']; ?>"><?php echo $row['id_empleado']; ?></a></td>
  42.                 <td><?php echo $row['nombre']; ?></td>
  43.                 <td><?php echo $row['email']; ?></td>
  44.                 <td><?php echo $row['telefono']; ?></td>
  45.             </tr>
  46.         <?php } ?>
  47.         </tbody>
  48.     </table>
  49. </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:
Código MySQL:
Ver original
  1. SELECT idusuarios, nombre, COUNT(idusuarios) TotalIds
  2. FROM seleccion
  3. GROUP BY idusuarios
  4. ORDER BY COUNT(idusuarios) DESC"
Así, en lugar de llamarla por "COUNT(idusuarios)", la invocas por "TotalIds".