Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/09/2015, 06:16
mblascog
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Esta sentencia sql no devuelve ningún registro

Buenas,
La siguiente sentencia, si la ejecuta en phpmyadmin, me devuelve muchos registros:

Código MySQL:
Ver original
  1. SELECT CONCAT(P.nombre_poblacion, ' (', COUNT(*), ')') AS pueblos FROM t_un U INNER JOIN t_poblacion P ON U.poblacion = P.id_poblacion WHERE U.tipo = 6 GROUP BY U.poblacion ORDER BY P.nombre_poblacion

En cambio, la misma, pasando por parámetro el tipo, devuelve 0 registros, y no sé ver porqué.

Código PHP:
Ver original
  1. <?php
  2.     $tipo = $_REQUEST["prm"];
  3.  
  4.     $consulta = "SELECT CONCAT(P.nombre_poblacion, ' (', COUNT(*), ')') AS pueblos FROM t_un U INNER JOIN t_poblacion P ON U.poblacion = P.id_poblacion WHERE U.tipo = ".$tipo." GROUP BY U.poblacion ORDER BY P.nombre_poblacion";
  5.     $qSelect =  mysql_query($consulta);
  6.     $registros = mysql_num_rows($qSelect);
  7.  
  8.     if ($registros > 0){
  9.         while ($fila = mysql_fetch_assoc($qSelect))
  10.             $retorn .= $fila['pueblos'];
  11.     }
  12.    
  13.     echo "Registros: ".$retorn;
  14. ?>

Alguien ve donde está el error? Gracias
__________________
Qué fácil cuando lo sabes y qué difícil cuando no