PHP로 응용 프로그램을 만들었고 TCPDF로 보고서를 작성했는데 문제가 없으며 select 쿼리가 제대로 실행됩니다. 그러나 데이터를 매우 조심스럽게 살펴보면 첫 번째 데이터가 누락 된 것으로 나타났습니다.내 쿼리 결과가 완료되지 않은 이유는 무엇입니까?
간단한 예제 쿼리 : 내가 MySQL의에서이 쿼리를 실행하면
이SELECT * FROM tb_expedition
, 모든 데이터가 표시됩니다. 쿼리가 내 PHP 프로그램에서 실행되면 결과는 아직 완료되지 않습니다. 총 데이터가 20 행인 경우 PHP에서 19 행만 표시되고 첫 번째 데이터가 누락됩니다. 에코 중 일부는 두 번째 줄은 정말 이상한 것을
$query = mysql_query($sql);
$data = mysql_fetch_array($sql);
while($data = mysql_fetch_array($query))
제거와이, 당신의 라인의 일부입니다
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// create new PDF document
include "koneksi.php";//conection file
$period=$_GET[PERIOD];
$sql = "SELECT * FROM tb_exp_expor where period = ' $period'";
$hasil = mysql_query($sql);
$data = mysql_fetch_array($hasil);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set font
$pdf->SetFont('times', '', 11);
// landscape
$pdf->addPage('L', 'LETTER');
$html = '
<table border="1" cellspacing="3" cellpadding="4">
<tr><td colspan="9" align="center"><h2>Form Pantauan Expedisi Export</h2></td></tr>
<tr>
<th align="center"><b>Tanggal</b></th>
<th align="center"><b>Nama Expedisi</b></th>
<th align="center"><b>Nama Distributor</b></th>
<th align="center"><b>Kota Tujuan</b></th>
<th align="center"><b>No Faktur</b></th>
<th align="center"><b>Kondisi Armada Pengiriman</b></th>
<th align="center"><b>Ketepatan Jumlah</b></th>
<th align="center"><b>Ketepatan Waktu Kirim</b></th>
<th align="center"><b>Keterangan</b></th>
</tr></table>';
$no=0;
while ($data = mysql_fetch_array($hasil))
{
$html .= '<table border="1"><tr><td align="center">'.$data['tgl'].'</td>
<td align="center">'.$data['nama_exp_expor'].'</td>
<td align="center">'.$data['nama_distributor'].'</td>
<td align="center">'.$data['kota_tujuan'].'</td>
<td align="center">'.$data['no_faktur'].'</td>
<td align="center">'.$data['kon_armada'].'</td>
<td align="center">'.$data['ketepatan_jml'].'</td>
<td align="center">'.$data['ketepatan_wkt_kirim'].'</td>
<td align="center">'.$data['ket'].'</td>
</tr></table> ';
$no++;
}
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('Daftar_Expedisi_Local', 'I');
?>
데이터를받는 PHP 코드에 문제가있을 가능성이 큽니다. 우리에게 보여줘. – DCoder
mysql 문이 좋다. 나머지 코드를 보여주십시오. –
@DCoder 코드 – MudMan23