Concatenate data of a user and print them only once

0

I'm working on scriptcase and managing pdfp to generate reports, but I have a problem.

I try to print the user's data in a single line, for example:

id ------nombre----------------- datos --------------fecha1 -------fecha2

1 ------ david puc poot ---------dato1,dato2,dato3- 15/dic/2016 15/enero/2017

2------ felipe cabrebra santos--- dato1,dato2,dato3,dato4-- 15/dic/2016 15/enero/2017

however I can not do it.
I'm handling this code:

foreach({rs} as $info){
    if($estPaciente != $info[0]  ){
        $estPaciente = $info[0];
        $servicio->CellFitScale(15,0,utf8_decode($info[0]),0,0,'L');
        $servicio->CellFitScale(125,0,utf8_decode($info[5]),0,0,'L');
        $servicio->CellFitScale(20,0,utf8_decode($info[1]),0,0,'L');
        $servicio->Cell(20,0,utf8_decode($info[2]),0,0,'L');
        $servicio->Ln(5);
    }

    if($estPaciente == $info[0]  ){
        $servicio->CellFitScale(100,0,utf8_decode($info[4]),2,0,'L');
        $servicio->Ln(5);
        $flag = true;
    }

}//fin de foreach

with this code I manage to do this

id --------- nombre -------datos--------- fecha1----------- fecha2

1 ----------david puc poot------  15/dic/2016---- 15/enero/2017

--------------------------dato1

--------------------------dato2

---------------------------dato3


2 ----------Felipe Cabrera------  15/dic/2016---- 15/enero/2017

--------------------------dato1

--------------------------dato2

---------------------------dato3

I hope you can help me, it must be simple but I can not figure out how.

My SQL throws me this result:

id*********nombre********descripcion*******fecha1***********fecha2

1**********david puc poot*********dato 1*******15/12/2016******17/01/2017

1**********david puc poot*********dato 2******15/12/2016******17/01/2017

1**********david puc poot*********dato 3*******15/12/2016******17/01/2017

2**********felipe cabrera*********dato 1*********15/12/2016******17/01/2017

2**********felipe cabrera*********dato 2***********15/12/2016******17/01/2017

2**********felipe cabrera*********dato 3*********15/12/2016******17/01/2017

2**********felipe cabrera*********dato 4**********15/12/2016******17/01/2017

2**********felipe cabrera*********dato 5**********15/12/2016******17/01/2017

To sort them I must make the descripcion field concatenate as long as the user is the same, so that at the moment of printing, only the user and the data of the descripcion field appear once.

    
asked by D. Puc Poot 15.12.2016 в 20:51
source

2 answers

0

The GROUP_CONCAT function allows you to concatenate strings in grouped queries.

Concatenate description by name

SELECT nombre, GROUP_CONCAT(descripcion SEPARATOR ' ')
FROM _nombreTabla_ 
GROUP BY nombre

Concatenate description by name and date

SELECT nombre, GROUP_CONCAT(descripcion SEPARATOR ' '), fecha1, fecha2 
FROM _nombreTabla_
GROUP BY nombre, fecha1, fecha2
    
answered by 16.12.2016 / 21:09
source
0

You can concatenate the fields of your select and simply send it to call, example:

SELECT CONCAT ('nombre', 'dato1', 'dato2') AS Result;  

The result of my sql is this:

id*********nombre*************descripcion************fecha1******fecha2

1**********david puc poot*********dato 1***********15/12/2016******17/01/2017
1**********david puc poot*********dato 2 *********15/12/2016******17/01/2017
1**********david puc poot*********dato 3***********15/12/2016******17/01/2017
2**********felipe cabrera*********dato 1 ********15/12/2016******17/01/2017
2**********felipe cabrera*********dato 2 ********15/12/2016******17/01/2017
2**********felipe cabrera*********dato 3 *********15/12/2016******17/01/2017
2**********felipe cabrera*********dato 4 *********15/12/2016******17/01/2017
2**********felipe cabrera*********dato 5 *********15/12/2016******17/01/2017

To sort them I must make the descripcion field concatenate as long as the user is the same so that at the moment of printing, only the user and the data of the descripcion field appear once.

    
answered by 15.12.2016 в 22:27