0
I’m having a little problem in my code, it’s generating the last blank page.
Follow the creation of this code with the help of the community: FPDF with Mysql and PHP - Bringing Repeated Data
I’ve already changed the variables, but to no avail.
$my_serial =["SERIAL1","SERIAL2","SERIAL3","SERIAL4","SERIAL5","SERIAL6","SERIAL7","SERIAL8","SERIAL9","SERIAL10","SERIAL11","SERIAL12","SERIAL13","SERIAL14","SERIAL15","SERIAL16","SERIAL17","SERIAL18","SERIAL19","SERIAL20","SERIAL1","SERIAL2","SERIAL3","SERIAL4","SERIAL5","SERIAL6","SERIAL7","SERIAL8","SERIAL9","SERIAL10","SERIAL11","SERIAL12","SERIAL13","SERIAL14","SERIAL15","SERIAL16","SERIAL17","SERIAL18","SERIAL19","SERIAL20","SERIAL21","SERIAL22","SERIAL23","SERIAL24","SERIAL25","SERIAL26","SERIAL27","SERIAL28","SERIAL29","SERIAL30","SERIAL31","SERIAL32","SERIAL33","SERIAL34","SERIAL35","SERIAL36","SERIAL37","SERIAL38","SERIAL39","SERIAL40","SERIAL41","SERIAL42","SERIAL43","SERIAL44","SERIAL45","SERIAL46","SERIAL47","SERIAL48","SERIAL49","SERIAL50","SERIAL51","SERIAL52","SERIAL53","SERIAL54","SERIAL55","SERIAL56","SERIAL57","SERIAL58","SERIAL59","SERIAL60","SERIAL61","SERIAL62","SERIAL63","SERIAL64","SERIAL65","SERIAL66","SERIAL67","SERIAL68","SERIAL69","SERIAL70"]; /// randomSerial(6,20,"lower_case,numbers");
$my_passwords =["SERIAL1","SERIAL2","SERIAL3","SERIAL4","SERIAL5","SERIAL6","SERIAL7","SERIAL8","SERIAL9","SERIAL10","SERIAL11","SERIAL12","SERIAL13","SERIAL14","SERIAL15","SERIAL16","SERIAL17","SERIAL18","SERIAL19","SERIAL20","SERIAL1","SERIAL2","SERIAL3","SERIAL4","SERIAL5","SERIAL6","SERIAL7","SERIAL8","SERIAL9","SERIAL10","SERIAL11","SERIAL12","SERIAL13","SERIAL14","SERIAL15","SERIAL16","SERIAL17","SERIAL18","SERIAL19","SERIAL20","SERIAL21","SERIAL22","SERIAL23","SERIAL24","SERIAL25","SERIAL26","SERIAL27","SERIAL28","SERIAL29","SERIAL30","SERIAL31","SERIAL32","SERIAL33","SERIAL34","SERIAL35","SERIAL36","SERIAL37","SERIAL38","SERIAL39","SERIAL40","SERIAL41","SERIAL42","SERIAL43","SERIAL44","SERIAL45","SERIAL46","SERIAL47","SERIAL48","SERIAL49","SERIAL50","SERIAL51","SERIAL52","SERIAL53","SERIAL54","SERIAL55","SERIAL56","SERIAL57","SERIAL58","SERIAL59","SERIAL60","SERIAL61","SERIAL62","SERIAL63","SERIAL64","SERIAL65","SERIAL66","SERIAL67","SERIAL68","SERIAL69","SERIAL70"]; ///randomPassword(5,20,"lower_case,numbers");
//////INICIA COM ESSAS DIMENSOES
$yincrementasenha = 28.5;
$yincrementaserial = 20.3;
$Xrepetedireita = 177.8;
$Xrepeteesquerda = 74;
$linhas = 0; // Máximo de linhas por página
$coluna = 1; // Contagem de colunas
$count_lines = 0; // Contagem de linhas na página
$linha1= 0;
$linha2= 0;
$total=0;
foreach (array_combine($my_serial, $my_passwords) as $serial2 => $dae1) {
if ($coluna === 1){
$pdf->SetY( $yincrementaserial ); # Define a posião para Cima ou para Baixo
$pdf->SetX($Xrepeteesquerda);
$pdf->Cell(150,10, $serial2,0,0); # Conteúdo do lado Esquerdo
$pdf->SetY( $yincrementasenha ); # Define a posião para Cima ou para Baixo
$pdf->SetX($Xrepeteesquerda);
$pdf->Cell(150,10, $dae1,0,0); # Conteúdo do lado Esquerdo
$coluna++; // Faz incremento na contagem de colunas[]
$linha1++;
}
elseif ($coluna === 2) {
$pdf->SetX($Xrepetedireita);
// Faz incremento na contagem de linhas
$pdf->SetY( $yincrementaserial ); # Define a posião para Cima ou para Baixo
$pdf->SetX($Xrepetedireita); # Define a posição para Esquerda ou para Direita
$pdf->Cell(0,10, $serial2,0,0); # Conteúdo do lado Direito
$pdf->SetY( $yincrementasenha ); # Define a posião para Cima ou para Baixo
$pdf->SetX($Xrepetedireita); # Define a posição para Esquerda ou para Direita
$pdf->Cell(0,10, $dae1,0,0); # Conteúdo do lado Direito
$coluna = 1; // Reset a contagem de colunas
$yincrementaserial = $yincrementaserial+58;
$yincrementasenha = $yincrementasenha+58;
$linha2++;
$total++;
}
/*
* Condição para verifcar se o números de linhas na página atual
* é maior que cinco, se for adiciona nova página e reset as variáveis
*/
if ($linha1 && $linha2 > 4){
$pdf->AddPage(); // Adiciona nova página
// Reset as variáveis para seus valores iniciais
$pdf->Image("imagemfundo.jpg", 0,0,210,295);
$count_lines = 0;
$linha2=0;
$linha1=0;
$total=$linha1;
$yincrementasenha = 28.5;
$yincrementaserial = 20.3;
}
}
$pdf->Output();
When I answered another question I created the variable
$linhas = 5;
and if you look you will notice that it is not used, but set its value to zero,$linhas = 0;
, within the while and after the condition add the line$linhas++;
, create a new variable before thewhile
and keep in it the number of records returned by the methodmysqli_query
ex:$registros = mysqli_num_rows($query);
– NoobSaibot
Change the condition to
if ($count_lines > 5 && $linhas < $registros)
, Obs.: There’s no way I can test at the moment.– NoobSaibot
I did according to your guidelines, but without success. I requested 100 vouchers, were generated 10 pages but the last comes with 2 blank vouchers.
– Michel Teixeira
I was left to add the $lines++ inside While, I made the correction.. but now instead of appearing 10 pages appear only 5 pages, as if counting every time you pass through a column... that is, dividing by two.
– Michel Teixeira
It worked for you @wmsouza?
– Michel Teixeira
I was checking the code now, and it’s funny that I created a table to simulate yours, and I put 101 records in them that total the 11 pages, and for me is normal. The only thing I changed there, was as I said in the first comment, that I was not using the variable
$linha
, leave it as it is before the comment and change only the leaving condition so:if ($count_lines >= $linhas)
– NoobSaibot
Not yet, I did according to your first comment, then I did according to the second changing only the
if ($count_lines >= $linhas)
but now it only shows one page. I returned to the original code, where it keeps leaving the last two vouchers blank... I don’t know why– Michel Teixeira
I changed the code in my question, in this mode is leaving the last two vouchers blank, I made your suggestions but it did not function.
– Michel Teixeira
See that within the condition
if ($count_lines > 5)
the variable$count_lines
is receiving the value 1 and was supposed to be receiving 0, make this change and change the condition toif ($count_lines >= $linhas)
and also change$linhas = 0;
for$linhas = 3;
that by the image of the other question I see that there are three lines per page.– NoobSaibot
see that I gave an update on the code, this is how it is now. Array with 70 codes, generating 8 pages, this way it is left a full page, ah and in the if I put > 4 because so I got the best result, when I add the > 5 adds only 6 pages, but to each page jump it is without 2 vouchers, example of the voucher 10 he jumps pro 13, then changes everything, where it was to end with 20 ends in 22, from 22 pula pro 25.
– Michel Teixeira