I need a web page generating a PDF file that returns multiple values for the same row in a sql db table. Right now it is working as it is getting the results I need, but only for table row number 1. But I have 1600+ rows and I would like to have the pdf with all rows.. (A4 pdf, with 2 results per page)
Code
<?php
require_once('include/menu.php');
include_once("mfpdf/mpdf.php");
include_once('include/ez_sql.inc');
setlocale(LC_MONETARY, 'pt_PT');
$socio = $db->get_results("SELECT * FROM socios where estado = 'ACTIVO'");
$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$mpdf -> allow_charset_conversion=true;
$mpdf->charset_in='utf-8';
// $stylesheet = file_get_contents('mfpdf/mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1); // *** The parameter 1 tells that this is css/style only and no body/html/text
$cont = 0;
foreach ($socio as $socio1) {
$cont = $cont + 1;
$ano = date("Y");
$idade = age(dtPadrao($socio->nascimento));
if ($idade >= 18) $Vquota = 1.50;
else $Vquota = 1;
$Vquota = money_format('%.2n', $Vquota);
$html = '
<br /><br />
<table width="794px" height="462px" align="center" style="border: 0px solid #880000; background-color: #FFF; " class="tallcells">
<tr>
<td height="462px" width="250px" valign="top" align="left">
<br><br><img src="img/sfal_logo.png" height="140px"><br><br><br>
<table border="2px" align="center">
<tbody>
<tr>
<td align="left"><font size="5"><h3>SOCIO Nº '.$socio1->n_socio.'</h3><br />
'.$socio1->nome.'<br />
'.$socio1->morada.'<br />
'.$socio1->cod_postal.' - '.$socio1->localidade.'<br />
<br />Ano '.$ano.'<br />
Valor Mensal: '.$Vquota.'
<br /><br />
Local de Cobrança:<br />
'.$socio1->local_cobranca.'</font><br />
</td>
</tr>
</tbody>
</table>
</td>
<td width="544px"> <!-- was 10px 10px-->
<table cellpadding="0px" cellspacing="15px" align="center">
<tbody>
<tr>
<td style="border: 1px solid #880000; background-color: #FFF;" width="190px" class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />DEZEMBRO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " width="190px" class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />NOVEMBRO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " width="190px" class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />OUTUBRO
<br />'.$ano.'</font></td>
</tr>
<tr>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />SETEMBRO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />AGOSTO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />JULHO
<br />'.$ano.'</font></td>
</tr>
<tr>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />JUNHO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />MAIO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />ABRIL
<br />'.$ano.'</font></td>
</tr>
<tr>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />MARÇO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />FEVEREIRO
<br />'.$ano.'</font></td>
<td style="border: 1px solid #880000; background-color: #FFF; " class="tallcells" align="center"><font size="5">
SFAL
<br />Sócio n.: '.$socio1->n_socio.'
<br />Valor: '.$Vquota.'
<br />JANEIRO
<br />'.$ano.'</font></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
<br /><br /><br />
';
//==============================================================
//==============================================================
//==============================================================
// $html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($html,2);
if ($cont == 50) break;
//==============================================================
//==============================================================
//==============================================================
}
$mpdf->Output('mpdf.pdf','I');
exit;
?>
based on the doc found here : https://ezsql.github.io/ezSQL/ez_sql_help.htm the method $db->get_row()
retreives only one row from the database. to get all the rows, you need to use $db->get_results()
instead
Then, you have to loop on the results using a foreach loop as shown on the example from the doc :
$users = $db->get_results("SELECT name, email FROM users");
foreach ( $users as $user )
{
// Access data using object syntax
echo $user->name;
echo $user->email;
}
Solved!!!
went with CROZET's sugestion and added a $count var to ease the html repetion.
thank you.