I'm trying almost everything to add a new key and its value to a result query.
$consulta = "SELECT p.id_empleado,count(p.id_empleado) as pendientes,e.nombre,e.apellidos FROM partidas_empleados p ";
$consulta.= "inner join empleados e on p.id_empleado=e.id_empleado ";
$consulta.= "WHERE abierta=TRUE group by id_empleado";
$sql = $con->prepare($consulta);
$ok = $sql->execute();
$query = $sql->fetchAll(PDO::FETCH_ASSOC);
for($i=0;$i<count($query);$i++){
//echo "hola";
$fila = $query[$i];
$consulta = "SELECT id_partida FROM partidas_empleados where id_empleado=? ";
$sql = $con->prepare($consulta);
$ok = $sql->execute(array($fila['id_empleado']));
$sub_query = $sql->fetchAll(PDO::FETCH_ASSOC);
//echo $sub_query;
//$fila[]= array("lista_partidas"=>$sub_query);
$fila['lista_partidas']= $sub_query;
}
$sub_query
is just a list of asociative arrays
I'm trying to add $sub_query
to $query
with lista_partidas
as a key.