I have made an application with php and a report with TCPDF, is no problem and the select query runs properly. But if I look at the data very carefully, I find the first data is missing.
Simple example query:
SELECT * FROM tb_expedition
If I run this query on MySQL, all of the data will appear. If the query is run from my php program, the result is still not complete. If the total data is 20 rows, in php appear only 19 rows, and the first data is missing.
This is my code:
<?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');
?>
These are some of your lines, with some of the echos removed
THat second line is really strange: you do an extra fetch_array, but with the sql-string as argument? That’s not really useful, doens’t that give an error?
You should clean up some of this code, for instance, don’t perform extra “fetch_array”‘s you don’t need. If it doesn’t function after that, remove all unneccesaire lines (echoes, colors, etc) that you do not need for debugging. You can more quickly find out what’s going on that way 🙂
While you’re at it, you should really look at moving from the
mysql_functions. Read this nice big read warning in the manual http://php.net/manual/en/function.mysql-fetch-array.phpNow try this please. THIS Is what you should have done in the first place as a “small as possible” example.
Please notice the: