0
I’m trying to set up a generator system Vouchers/Tickets
I have a table in SQL with the name Vouchers with multiple users and their respective passwords.
I call in each Cell the variable $serial_voucher
and $senha_voucher
But it only shows the first line and applies in all Cell.
Thank you, I’m grateful if someone can give me that strength.
<?php
$con = mysqli_connect('localhost','root','');
mysqli_select_db($con,'voucherss');
$query=mysqli_query($con,"select *from vouchers");
while($data=mysqli_fetch_array($query)){
//A4 WIDTH : 219MM
require ('pdf/fpdf.php');
$pdf = new Fpdf ('p','mm','A4');
$pdf->AddPage();
$pdf->Image("imagemfundo.jpg", 0,0,210,295);
$pdf->SetFont('Arial','','8');
$pdf->SetY( 20.3 );///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['serial_voucher'],0,0,'L'); /////ESQUERDA 1
$pdf->SetY( 28.1);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['senha_voucher'],0,0,'L'); /////ESQUERDA 1
$pdf->SetY( 20.3);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 177.8 ); ///LADOS
$pdf->Cell( 0,10, $data['serial_voucher'], 0, 0, '' ); /////DIREITA 1
$pdf->SetY( 28.4); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 177.8 ); ///LADOS
$pdf->Cell( 0,10, $data['senha_voucher'], 0, 0, '' ); /////DIREITA 1
$pdf->SetY( 78.8 ); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['serial_voucher'],0,0,'L'); /////ESQUERDA 2
$pdf->SetY( 86.3); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['senha_voucher'],0,0,'L'); /////ESQUERDA 2
$pdf->SetY( 78.5); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 178 ); ///LADOS
$pdf->Cell( 0,10, $data['serial_voucher'], 0, 0, '' ); /////DIREITA 2
$pdf->SetY( 86.3);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 178 ); ///LADOS
$pdf->Cell( 0,10, $data['senha_voucher'], 0, 0, '' ); /////DIREITA 2
$pdf->SetY( 136.5);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['serial_voucher'],0,0,'L'); /////ESQUERDA 3
$pdf->SetY( 144.3);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['senha_voucher'],0,0,'L'); /////ESQUERDA 3
$pdf->SetY( 136.5);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 177.8 ); ///LADOS
$pdf->Cell( 0,10, $data['serial_voucher'], 0, 0, '' ); /////DIREITA 3
$pdf->SetY( 144.4); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 177.8 ); ///LADOS
$pdf->Cell( 0,10, $data['senha_voucher'], 0, 0, '' ); /////DIREITA 3
$pdf->SetY( 194.8 ); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['serial_voucher'],0,0,'L'); /////ESQUERDA 4
$pdf->SetY( 202.7); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['senha_voucher'],0,0,'L'); /////ESQUERDA 4
$pdf->SetY( 194.8); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 178 ); ///LADOS
$pdf->Cell( 0,10, $data['serial_voucher'], 0, 0, '' ); /////DIREITA 4
$pdf->SetY( 202.7);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 178 ); ///LADOS
$pdf->Cell( 0,10, $data['senha_voucher'], 0, 0, '' ); /////DIREITA 4
$pdf->SetY( 252.8 ); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['serial_voucher'],0,0,'L'); /////ESQUERDA 5
$pdf->SetY( 260.6); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 74 ); ///LADOS
$pdf->Cell(0,10,$data['senha_voucher'],0,0,'L'); /////ESQUERDA 5
$pdf->SetY( 252.8); ///PRA CIMA OU PRA BAIXO
$pdf->SetX( 178 ); ///LADOS
$pdf->Cell( 0,10, $data['serial_voucher'], 0, 0, '' ); /////DIREITA 5
$pdf->SetY( 260.6);///PRA CIMA OU PRA BAIXO
$pdf->SetX( 178 ); ///LADOS
$pdf->Cell( 0,10, $data['senha_voucher'], 0, 0, '' ); /////DIREITA 5
$pdf->Output();
}?>
Welcome, I recommend you to do the Tour, Knowing your problem, this is happening because it is inside the loop of repetition
while
, put out of the loop what is not to be repeated, type data that are entered manually by you.require ('pdf/fpdf.php');
wasn’t supposed to be inside the loop.– NoobSaibot
Okay, I was able to understand, I did some other small systems where I worked with the HTML columns, was it enough to insert While with <tr></tr> and its <td>? php echo $Rows['id'];? ></td> and ready. - But in this case, I need to configure the position of each Cell in the FPDF to fit exactly in the Input of the template.pdf for this reason I am repeating the variable in each Cell. I believe the problem is there, but how else could I do it?
– Michel Teixeira
What data is not to repeat? Place this line
$pdf = new Fpdf ('p','mm','A4');
and that too$pdf->Output();
out of thewhile
– NoobSaibot
Example. I have a table with Serial columns and password. User 1 | Password1 User 2 | Password 2 And so on, but for some mistake in the code is only bringing the first line, User 1 | Password 1, and in each voucher should go a different user and password. Is showing the correct data but I want you to show all and not only the first line.
– Michel Teixeira
You want the data in one PDF just ? If not, just put the lines
require ('pdf/fpdf.php'); $pdf = new Fpdf ('p','mm','A4');
before thewhile
and the line$pdf->Output();
after thewhile
.– NoobSaibot
@Souza look, with your suggestion now seems to be improving, now it is writing different data but on each page, example Page 1 User 1 | Password 1 and repeats until the next page... Page 2. User 2 | Password 2 and repeats as well. Summarizing: You are listing all database data but on one page for each user.
– Michel Teixeira
Put the
$pdf->Output();
within thewhile
again to see if it helps. There’s no way I can test now if I wouldn’t talk exact to you.– NoobSaibot
I did as you suggested, but we returned to the point 0 hehe. It did not work.
– Michel Teixeira
Okay, strip again, put also before the
while
the line$pdf->AddPage();
for it is she who adds new page, now I see that you are calling several times$pdf->SetY
and$pdf->SetX
, loop and row by row of returned result, so if you repeat these class methods FPDF within the loop will only repeat the data of the current line and not the next one, so that it works you must create conditions, something thus then makes the sum to position the objects.– NoobSaibot
Blz, I have followed your guidelines and other web tutorials such as http://www.fpdf.org/en/script/script30.php http://www.fpdf.org/en/script/script14.php Follow my current code. https://repl.it/repls/UnwittingOverjoyedKentrosaurus For the time being, printing the data only on the first card of each page, it is also repeating the same information on the right and left sides. desperation beating rsrsrs
– Michel Teixeira