0
Hello, everybody.
I have a little problem and I can’t get out of it. Here’s the problem:
I need to generate a pdf (report) with some data coming from a mysql query. So far, so good! But all this code that will appear in the pdf is being generated via PHP script mixed with HTML. In the middle of this code, I call a function and I need to display its result within an HTML snippet, here that is the problem, I can’t get the correct syntax of the foreach loop that is inside this HTML. Follow the code excerpt:
$montagem = "<!DOCTYPE html>
<html lang='pt-br'>
<head>
<meta charset='utf-8'>
</head>
<body>
<h1 style='font-size: 12px; text-align: center;'>ATESTADO ZOOSSANITÁRIO PARA
CAPRINOS</h1>
<table style='width: 100%; margin: 0 20px;'>
<h1 style='font-size: 13px; text-align: center;'>IDENTIFICAÇÃO DOS ANIMAIS</h1>
<table cellspacing='0px' cellspadding='0px' style='width: 100%; margin: 0 20px;'>
<tr style='text-align: center; vertical-align: middle;'>
<td rowspan='2' style='border: 1px solid #000; border-right: 0 none; padding: 0;'>Ordem</td>
<td rowspan='2' style='border: 1px solid #000; border-right: 0 none;'>Espécie</td>
<td rowspan='2' style='border: 1px solid #000; border-right: 0 none;'>Raça</td>
<td colspan='2' style='border: 1px solid #000; border-right: 0 none; border-bottom: 0 none;'>Nº por Sexo</td>
<td rowspan='2' style='border: 1px solid #000;'>Total</td>
</tr>
<tr style='text-align: center;'>
<td style='border: 1px solid #000; border-right: 0 none;'>Macho</td>
<td style='border: 1px solid #000; border-right: 0 none;'>Fêmea</td>
</tr>
foreach ($caprinos2 as $caprino) {
<tr class='text-center'>
<td>echo $caprinos2[capregistro]</td>
<td>$caprinos2[especie]</td>
<td>$caprinos2[raca]</td>
<td>$caprinos2[qtdmacho]</td>
<td>$caprinos2[qtdfemea]</td>
<td>$caprinos2[municipio]</td>
</tr>
}
</table>
</body>
</html>";
Someone would have an idea how to display the foreach loop result?
Hello, William. Thank you for your help! But by making the following adjustments he is accusing the following error in the variables to be displayed: "Notice: Undefined index: capregistro in"
– Vandré Paulo
@Vandrépaulo This error has nothing to do with the adjustments. If you get google translator will know what it means, the problem is in your variable
$caprinos2
that you didn’t even post in the question, ie it has nothing to do with the foreach.– Guilherme Nascimento
True, William, true, true. This last problem was in the index of the variable I used to receive the function created at the beginning of the file, which I did not mention in the initial problem. I already solved, without the help of Google Translator. Thank you very much for the tip, it was of great value to my problem! A strong hug!
– Vandré Paulo