Ver Mensaje Individual
  #3 (permalink)  
Antiguo 28/01/2016, 09:57
tonigomila1988
 
Fecha de Ingreso: mayo-2011
Ubicación: Palma de Mallorca
Mensajes: 108
Antigüedad: 13 años
Puntos: 4
Respuesta: Consultar si tabla esta vacía PDO

Al final he hallado la solución. Dejo aquí el código:

Código PHP:
Ver original
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8" />
  5.         <title>Empresas asociadas</title>
  6.     </head>
  7.     <body>
  8.         <a href="alta.html">Alta</a><br/>
  9.         <?php
  10.             //llamada al archivo de los datos de conexion y conectar a la base de datos.
  11.             require_once 'inc/db.inc';
  12.             connectDB();
  13.             // preparar sentencia sql a ejecutar.
  14.             $sql = "SELECT COUNT(*) as count FROM $dbtable";
  15.             $stmt = $connect->prepare($sql);
  16.             // ejecutar sentencia
  17.             $stmt->execute();
  18.             // guardamos el resultado como un array
  19.             $row = $stmt->fetch(PDO::FETCH_ASSOC);
  20.             closeDB();
  21.             // si el indice count es 0, deshabilitamos la modificacion y dar baja
  22.             if($row['count'] == 0)
  23.             {
  24.                 echo '<input type="button" value="Modificar" disabled /><br/>';
  25.                 echo '<input type="button" value="Eliminar" disabled /><br/>';
  26.             }
  27.             else
  28.             {
  29.                 echo '<input type="button" value="Modificar" /><br/>';
  30.                 echo '<input type="button" value="Eliminar" /><br/>';
  31.             }
  32.             /*
  33.             $stmt = $connect->query($sql);
  34.             // ejecutamos la sentencia y comprobamos si cuenta filas de la tabla
  35.             $stmt->execute();
  36.             $row = $stmt->fetch(PDO::FETCH_ASSOC);
  37.             if($row)
  38.             {
  39.                 echo '<input type="button" value="Modificar" /><br/>';
  40.                 echo '<input type="button" value="Eliminar" /><br/>';
  41.             }
  42.             else
  43.             {
  44.                 echo '<input type="button" value="Modificar" disabled /><br/>';
  45.                 echo '<input type="button" value="Eliminar" disabled /><br/>';
  46.             }
  47.             */
  48.            
  49.         ?>
  50.     </body>
  51. </html>