2016-10-04 3 views
0

나는 테이블의 PDF를 생성하기 위해 TCPDF 라이브러리를 사용하고 있습니다.PHP 마지막 줄만 표시하는 루프

테이블 행이 두 행 중 10

이 같은 송장 번호 을 가지고 말의 몇 가지 번호가 "78650"

지금 나는 송장 번호에 의해 선택입니다 원하는대로 그것은을 가진 PDF를 생성해야 두 행.

대신 두 번째 행이 마지막 행인 개를 가져 오는 중입니다. 그건 연속 2 번만 찍은 것입니다. 다음은

코드 :

<?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'); 
?> 
+1

'$ html2' 변수를 연결해야합니다. –

답변

1

반복에 대해 당신이 $html2의 내용을 대체하고 있기 때문이다. 대신 콘텐츠를 추가해야합니다.

따라서 빈 변수 $html2을 루프 외부로 가져 와서 루프를 반복하면서 결과를 추가하십시오.

코드

$html2=""; 
while($row = mysqli_fetch_array($result)){ 
$pr = $row['product']; 
$dr = $row['description']; 
$qty = $row['qty']; 
$total = $row['total']; 

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

$i++; 

} 
+0

오 죄송합니다. 감사합니다 .. 친구처럼 일했습니다 .. –

+0

굉장. 문제가 해결되면 정답으로 수락하십시오. –

+0

완료되었습니다. 감사 –

1

두 번째 패치는 변수 $ HTML2을 덮어, 다음과 같이 보일 것입니다. 배열 $ html2 [$ i]를 사용할 수 있습니다.

0
$tbl_header = '<table border="1"><tr> 
     <th>FirstName</th><th>LastName</th><th>Gender</th><th>E-Mail</th><th>Mobile</th><th>DateOfBirth</th><th>Country</th><th>State</th><th>City</th><th>Address</th><th>Zipcode</th><th>File</th></tr>'; 
$tbl_footer = '</table>'; 

$tbl = ''; 
while($row = mysqli_fetch_array($result)) 
    { 
$tbl .= ' 
<tr><td>'.$row['firstname'].'</td><td>'.$row["lastname"].'</td><td>'.$row["sex"].'</td><td>'.$row["email"].'</td><td>'.$row["mobile"].'</td><td>'.$row["dob"].'</td><td>'.$row["country"].'</td><td>'.$row["state"].'</td><td>'.$row["city"].'</td><td>'.$row["address"].'</td> 
<td>'.$row["zipcode"].'</td> 
<td><img src="'.$row["file"].'"/></td> 
</tr> 
'; 

} 
//$pdf->writeHTML($html, true, false, true, false, ''); 
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, ''); 
관련 문제