Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:00:52+00:00 2026-06-09T00:00:52+00:00

I have made an application with php and a report with TCPDF, is no

  • 0

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');

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:00:53+00:00Added an answer on June 9, 2026 at 12:00 am

    These are some of your lines, with some of the echos removed

     $query = mysql_query($sql);
     $data = mysql_fetch_array($sql);
     while($data = mysql_fetch_array($query))
    

    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.php

    Suggested alternatives

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL
    extension should be used. See also MySQL: choosing an API guide and
    related FAQ for more information. Alternatives to this function
    include:

    mysqli_fetch_array()
    PDOStatement::fetch()

    Now try this please. THIS Is what you should have done in the first place as a “small as possible” example.

    <?php
      include "koneksi.php";//conection file
      $period=$_GET[PERIOD];  
      $sql = "SELECT * FROM tb_exp_expor where period = ' $period'";
      var_dump($sql);//you can check this query in your database manually
    
      $hasil = mysql_query($sql);       
      //NO FETCH ARRAY HERE!
    
       while ($data = mysql_fetch_array($hasil)){
            var_dump($data);
        }
    
    ?>
    

    Please notice the:

    1. REMOVAL of the extra fetch array.
    2. REMOVAL of all the HTML and PDF stuff for debugging
    3. SMALL, as much as possible self-contained code.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I have made an application and I have installed it on my iphone, but
I have made a C# application that talks to my website via PHP(mcrypt) and
I have made an application with PHP. I am not an OOP developer and
I have made an iframe style facebook application that uses php and javascript (jquery).
I am not very experienced with database and php and I have a problem.
I have a PHP web application where I've made a little module system, that
I made a very simple Facebook application in PHP that retrives information about the
I have made an application for IPad in objective C. In this I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.