-1
I have a big problem. I have a PHP/LARAVEL system that issues PDF reports. The system it is omitting an element when placing it in an array.
I believe it’s time to assemble the loop and make the comparisons of if I’m missing something.
I have a list of people and I have to list 9 people per page, the 10 person who should be on the next page does not appear he jumps this person and the fact repeats itself every 10 elements. The solution may be simple but I’m not thinking.
NOTE: The return of the elements in the database brings all people.
$Serv[$p][$j] = $server; where [$p] is the page and the [$j] element on the page
I hope you can help me.
$i = 0;
$j = 0;
$p = 0;
$dep = '';
$pdep = '';
$aux = count($servidores);
foreach ($servidores as $value => $servidor) {
$servidor->ferias = $ferias[$value]->ferias;
if($value == 0){
$pdep = $servidor->cd_departamento;
$dep = $servidor->cd_departamento;
$serv[$p][$j] = $servidor;
$j++;
}else{
if($dep == $servidor->cd_departamento){
if ($j < 9) {
$serv[$p][$j] = $servidor;
$j++;
} else {
$p++;
$j = 0;
$serv[$p][$j] = $servidor;
}
}else{
$dep = $servidor->cd_departamento;
$p++;
$j = 0;
$serv[$p][$j] = $servidor;
}
}
}
$servidores_separados_por_pagina = array_chunk($servidores, 9);
– Adir Kuhn
I ended up not explaining, but the system has a peculiarity, if the person is from a different department than the previous person he should start a new page.
– douglas pjuizfora
has to send the contents of the variable servers?
– Adir Kuhn
@douglaspjuizfora, and how do you know the person belongs to a different department?
– Victor Carnaval
It comes with all the records of the server object. When putting this object inside the array is where the problem is. He is commenting on the elements 10,20,30,40 and so on that in the code would be the elements (9,19,29,39 ...)
– douglas pjuizfora
@Vitor Carnaval, I save the elements in the variables "$pdep = $server->cd_departamento; $Dep = $server->cd_departamento; and I compare whether or not I moved to the last server.
– douglas pjuizfora
In the variable $servers, it brings ALL the elements right, Now when it comes to throwing the object inside these arrays it does not put the (9,19,29,39...)
– douglas pjuizfora