SQL query does not show table in PHP

1

I have a query in sql that in the phpmyadmin shows what I need, but when I pass it to the php file it does not show anything, and if I remove the group by it only shows me a row, any suggestions !! (IT WORKS IN MYSQL BUT IN PHP NO)

<?php
if(isset($_POST['tag'])){
  try{
    $conn = new PDO('mysql:host=localhost;dbname=dbregistroscajero;charset=UTF8','root','');

    $sql = "SELECT empleados.noEmpleado, empleados.nombre, fechaHoraS, count(registro) as total from registro inner join empleados on registro.empleado = empleados.noEmpleado where date_format(fechaHoraS, '%Y-%m-%d') >='2016-02-16' order by fechaHoraS desc limit 0,300";

    $result = $conn->prepare($sql)or die($sql);

    if(!$result->execute()) return false;

    if($result->rowCount() > 0){
      $json=array();

      while($row=$result->fetch()){
        $json[]=array(
          'Dato1' => $row['noEmpleado'],
          'Dato2' => $row['nombre'],
          'Dato3' => $row['fechaHoraS'],
          'Dato4' => $row['nombre'],
          'Dato5' => $row['total']
        );
      }
      $json['success'] = true;
      echo json_encode($json);
    }

  }catch(PDOException $e){
    echo 'Error: ' .$e->getMessage();
  }
}
?>
    
asked by matteo 17.03.2016 в 18:57
source

1 answer

1

I think the problem is in the query: you are using an aggregation function ( count ) you should try to place a group by to the other fields within the query.

   group by empleados.noEmpleado, empleados.nombre, fechaHoraS
    
answered by 17.03.2016 / 21:56
source