have this code to generate multiple table from a db. The problem is that a don't know how to close the table, because I have some rules inside my php with if and else
<?php
mysql_connect("localhost","root","");
mysql_select_db('test');
$barcode_cliente='1111111111111';
$sql="SELECT ora, prezzo, data, prodotto, SUM(quantita) as QtyTotal, SUM(totale_parziale) as Sumtotale_parziale
FROM barcode_consumazioni
GROUP BY
ora, data, prodotto";
$result=mysql_query($sql);
$dates_precedente = NULL;
while($row=mysql_fetch_array($result)){
$dates="Ordine del ".$row["data"]." delle ore ".$row["ora"];
if ($dates === $dates_precedente) {
echo '<tr>
<td>'.$row["prodotto"].'</td>
<td> x'.$row["QtyTotal"].'</td>
<td>'.number_format($row["prezzo"],2,",",".").' €</td>
<td>'.number_format($row["Sumtotale_parziale"],2,",",".").' €</td>
</tr>';
}
else
{
echo '<table style="text-align:center; margin-top:20px;" align="center" cellpadding="5">
<caption><u><b>'.$dates.'<b/></u><br /></caption>
<thead style="background-color:#EBE9E9">
<tr >
<th scope="col">Prodotto</th>
<th scope="col">Quantità</th>
<th scope="col">Prezzo</th>
<th scope="col">Totale parziale</th>
</tr>
</thead>
<tbody style="background-color:F5FFFF">
<tr>
<td>'.$row["prodotto"].'</td>
<td> x'.$row["QtyTotal"].'</td>
<td>'.number_format($row["prezzo"],2,",",".").' €</td>
<td>'.number_format($row["Sumtotale_parziale"],2,",",".").' €</td>
</tr>
</tbody></table>';
}
$dates_precedente = $dates;
}
?>
Now the problem is that if dates is unique I can close the table, but if $dates is not unique it generates others rows. I'm trying to find a rule that say, when $dates===$dates_precedente and it is the last, so you can put also </tbody></table>