PHP Mientras que el bucle muestra solo la última fila

Estoy usandoTCPDF biblioteca para generar PDF de una tabla.

La tabla tiene pocas filas, digamos 10

Entre esas dos filas tiene el mismo número de factura"78650"

Ahora yo soyselección por número de factura y si lo desea, debe generar PDF condos filas.

Pero en cambio, solo está buscandosegunda fila Esa es la última fila. Es decir, solo se toma el número de serie 2.

Código a continuación:

<?php
require_once('TCPDF/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', '', 9);
$pdf->AddPage();

$html1 = '<table  cellspacing="0" class="table table-striped">
<tr>

<th>SL No.</th>

<th>Product</th>
<th>Description</th>
<th>Qty</th>
<th>Total</th>
</tr>';

$sql = ("select * from invoice WHERE invoice_no = 78650 ORDER BY invoice_id ASC");
$result=mysqli_query($connection,$sql);
$i = 1;
while($row = mysqli_fetch_array($result)){
$pr = $row['product'];  
$dr = $row['description'];  
$qty = $row['qty']; 
$total = $row['total']; 

$html2 =  "<tr>

<td>".$i."</td>                         
<td>".$pr."</td>
<td>".$dr."</td>
<td>".$qty."</td>
<td>".$total."</td>
</tr>";

$i++; } 

$sql_1 = ("select *,SUM(total)as tot from invoice WHERE invoice_no = 78650 GROUP BY invoice_no");
$result_1=mysqli_query($connection,$sql_1);
$row_1 = mysqli_fetch_array($result_1);
$tot = $row_1['tot']; 
$html3 =    "<tr>
<td></td>

<td></td>
<td></td>
<td>Total: </td>
<td>".$tot."</td>
</tr>                       
</table>";
$html = $html1.$html2.$html3;
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('htmlout.pdf', 'I');
?>

Respuestas a la pregunta(3)

Su respuesta a la pregunta