Change PDF background according to bank data (PHP, MYSQL, FPDF)

1

I'm trying to customize my report in FPDF , it's a system that generates discount tickets, where they are printed in batches, for example batch of 50 units. Tickets on this lot will have the same profile where it can be 10%, 20% and 30% off. I would like to customize the background according to the profile.

I would like to know the profile of only one of the ticket's to make the comparison since the profile is the same for all of the lot

$result_tickets = "SELECT * FROM vouchers WHERE serial_lote = '112027511417'";
$resultado = mysqli_query($conn, $result_tickets);

$registros = mysqli_num_rows($resultado);

////ME VEIO ESTA IDEIA, PORÉM NÃO ESTÁ FUNCIONANDO..

$perfil_desconto = $resultado['desconto'];
if ($perfil_desconto == '10%') {

   $template_background = "template-10.jpg";

} elseif ($perfil_desconto == '20%') {

   $template_background = "template-20.jpg";

}  elseif ($perfil_desconto == '30%') {

   $template_background = "template-30.jpg";

}  elseif ($perfil_desconto == '50%') {

   $template_background = "template-50.jpg";

} 

$pdf = new Fpdf ('p','mm','A4');
$pdf->SetAutoPageBreak(false);
$pdf->SetFont('Arial','','10');
$pdf->AddPage();
$pdf->Image("$template_background", 0,0,210,295);

Remembering that While has yet to pull all the data from the database and inserts it into the PDF, but I did not find it necessary to insert it here.

    
asked by anonymous 28.11.2017 / 15:43

1 answer

1

The problem is in this line $perfil_desconto = $resultado['desconto']; . You can not identify because the variable $resultado is related to the query object.

One option would be to add mysqli_fetch_array to do this:

$resultado = mysqli_query($conn, $result_tickets);

$registros = mysqli_num_rows($resultado);

$reg = mysqli_fetch_array($resultado); // aqui eu adicionei

////ME VEIO ESTA IDEIA, PORÉM NÃO ESTÁ FUNCIONANDO..

$perfil_desconto = $reg['desconto'];
if ($perfil_desconto == '10%') {

   $template_background = "template-10.jpg";

} elseif ($perfil_desconto == '20%') {

   $template_background = "template-20.jpg";

}  elseif ($perfil_desconto == '30%') {

   $template_background = "template-30.jpg";

}  elseif ($perfil_desconto == '50%') {

   $template_background = "template-50.jpg";

} 

If not, please comment here.

    
28.11.2017 / 20:04