2017-05-19 18 views
0

TCPDFを使用してpdfを作成しようとしていますが、pdfに何も表示されていません。検索後に呼び出されるデータは表示されません。 NB私はまた、2つのテーブル間の結合を使用しました。TCPDFを使用してpdfにデータを挿入する方法

<?php 
ob_start(); 
function fetch_data(){ 
$output=""; 

if(isset($_POST["btnSearch"])) 
{ 


if (isset($_POST['txtNameSearch'])){ 
$search = $_POST['txtNameSearch']; 

$connection = mysqli_connect('localhost', 'root', '', 'bookstore'); 
$sql="SELECT * FROM order_details right join tblproduct on 
order_details.prod_id=tblproduct.prod_id WHERE id_login = $search"; 
$Joined_records=mysqli_query($connection,$sql); 
while ($row=mysqli_fetch_assoc($Joined_records)){ 
    $output .=' 
     <tr> 
      <td>'.$row["order_details_id"].'</td> 
      <td>'.$row["order_id"].'</td> 
      <td>'.$row["prod_id"].'</td> 
      <td>'.$row["id_login"].'</td> 
      <td>'.$row["quantity"].'</td> 
      <td>'.$row["price_per_unit"].'</td> 
      <td>'.$row["prod_name"].'</td> 
      <td>'.$row["prod_descr"].'</td> 
      <td>'.$row["prod_cat"].'</td> 
      <td>'.$row["prod_price"].'</td> 
      <td>'.$row["prod_quan"].'</td> 
     </tr> 
    '; 

              } 
    return $output;           
           } 
} 

       } 



if(isset($_POST["create_pdf"])) 
{ 
require_once("tcpdf/tcpdf.php"); 
$obj_pdf = new TCPDF('P',PDF_UNIT,PDF_PAGE_FORMAT,true,"UTF-8",false); 
$obj_pdf->SetCreator(PDF_CREATOR); 
$obj_pdf->SetTitle("product sales for a specific customerproduct sales for a 
specific customer"); 
$obj_pdf->SetHeaderData("","", PDF_HEADER_TITLE, PDF_HEADER_STRING); 
$obj_pdf->SetHeaderFont(Array(PDF_FONT_NAME_MAIN,"",PDF_FONT_SIZE_MAIN)); 
$obj_pdf->SetFooterFont(Array(PDF_FONT_NAME_DATA,"",PDF_FONT_SIZE_DATA)); 
$obj_pdf->SetDefaultMonospacedFont('helvetica'); 
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 
$obj_pdf->SetMargins(PDF_MARGIN_LEFT,'5',PDF_MARGIN_RIGHT); 
$obj_pdf->SetPrintHeader(false); 
$obj_pdf->SetPrintFooter(false); 
$obj_pdf->SetAutoPageBreak(TRUE,10); 
$obj_pdf->SetFont('helvetica',"",12); 
$obj_pdf->AddPage(); 

$content=""; 
$content.=' 
    <h3 align="center"> product sales for a specific customer </h3> 
    <table border="1" cellspacing="0" cellpadding="5"> 
     <tr> 
      <th width=9%>order_details_id</th> 
      <th width=9%>order_id</th> 
      <th width=9%>product_id</th> 
      <th width=9%>id_login</th> 
      <th width=9%>quanitity</th> 
      <th width=9%>price_per_unit</th> 
      <th width=9%>prod_name</th> 
      <th width=25%>prod_descr</th> 
      <th width=9%>prod_cat</th> 
      <th width=9%>prod_price</th> 
      <th width=9%>prod_quan</th> 
     </tr> 
'; 

$content .= fetch_data(); 
$content .= '</table>'; 
$obj_pdf->writeHTML($content); 
$obj_pdf->Output("sample.pdf","I"); 



} 
    ?> 

<html> 
<head> 
    <title>product sales for a specific customer</title> 
    <link rel="stylesheet" type="text/css" href="css/style.css" /> 
</head> 
<body> 
     <h3 align="center"> Please Search for a specific customer you want to see sales for: </h3> 
     <br /> 
     <form method="POST" action="index.php"> 
     <input type="text" name="txtNameSearch" /> 
     <input class="src_btn" type="submit" name="btnSearch" value="Search" /> 
     </form> 
      <table width="800" border="1" cellpadding="1" cellspacing="1"> 
      <tr> 
      <th>Order Details Id</th> 
      <th>Order ID</th> 
      <th>Product Id</th> 
      <th>Login ID</th> 
      <th>Quantity</th> 
      <th>Product Price per unit</th> 
      <th>Product Name</th> 
      <th>Product Descrp</th> 
      <th>Genre</th> 
      <th>Price</th> 
      <th>Quantity Sold</th> 
      </tr> 
       <form method="post"> 
       <input type="submit" name="create_pdf" class="btn btn- 
danger" value="create_pdf" /> 
      </form> 





<?php 
echo fetch_data(); 
?> 

答えて

0

あなたのPDFの前に何かが出力されているようです。他の何よりも先にPHPコード全体を移動してみてください。 Fatal error: Some data has already been output, can't send PDF file

EDIT:すべてのPHPコードを一番上に置いたので、それでも同じことが起こると、PHPコードに警告またはエラーがあることを意味します。 ob_start()のためにそれを見ることはできません。だから、何が起こっているのかを見るには、ob_start();行を一時的にコメントアウトして、一番上に最初の行にerror_log(E_ALL);行を入れてください。また、$obj_pdf->Output("sample.pdf","I");行の直前にdie();行を置く。スクリプトを実行します。ページ上に何も印刷されていない(と何かを意味する)が表示された場合、これは問題であり、表示されるエラーまたは警告を修正する必要があります。

+0

私は質問を言い換えてください。 –

+0

私の編集した答えを見てください。 –

+0

この@MOHAMMEDAMEENに関する最新情報はありますか?私の問題を理解できなかった場合は、あなたの最初の質問が変更されたように見えるかもしれませんが、あなたの質問をきれいにして言い換えてください。 –

関連する問題