2016-06-17 10 views
-1

データベースの内容をpdf形式で出力するこのPHPスクリプトがあります。 「Parse error:構文エラーです。予期しない '$ y_axis'(T_VARIABLE)in ..」この行
どうすればこの問題を解決できますか? //次の行に移動 $ y_axis = $ y_axis + $ row_height;MYSQLテーブルのデータレコードをPDFに変換する方法

<?php 
include('FPDF-master/font'); 
require('FPDF-master/fpdf.php'); 

//Connect to your database 
$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "test"; 

    // Create con 

$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
die("Connection failed: " . $conn->connect_error); 
} 


//Create new pdf file 
$pdf=new FPDF(); 

    //Disable automatic page break 
$pdf->SetAutoPageBreak(false); 

//Add first page 
$pdf->AddPage(); 

//set initial y axis position per page 
$y_axis_initial = 25; 

//print column titles 
$pdf->SetFillColor(232,232,232); 
$pdf->SetFont('Arial','B',12); 
$pdf->SetY($y_axis_initial); 
$pdf->SetX(25); 

$pdf->Cell(30,6,'name',1,0,'L',1); 
$pdf->Cell(100,6,'amount',1,0,'L',1); 
$pdf->Cell(30,6,'trans_id',1,0,'R',1); 
$pdf->Cell(30,6,'time_paid',1,0,'R',1); 

    $y_axis = $y_axis + $row_height; 

    //Select the Products you want to show in your PDF file 
$result=mysql_query('SELECT name, amount, trans_id, msisdn, time_paid FROM customer',$link); 

//initialize counter 
$i = 0; 

//Set maximum rows per page 
$max = 25; 

//Set Row Height 
$row_height = 6; 

while($row = mysql_fetch_array($result)) 
{ 
//If the current row is the last one, create new page and print column title 
if ($i == $max) 
{ 
    $pdf->AddPage(); 

    //print column titles for the current page 
    $pdf->SetY($y_axis_initial); 
    $pdf->SetX(25); 
    $pdf->Cell(30,6,'name',1,0,'L',1); 
    $pdf->Cell(100,6,'amount',1,0,'L',1); 
    $pdf->Cell(30,6,'trans_id',1,0,'R',1); 
    $pdf->Cell(30,6,'time_paid',1,0,'R',1) 

    //Go to next row 
    $y_axis = $y_axis + $row_height; 

    //Set $i variable to 0 (first row) 
    $i = 0; 
} 

$name = $row['name']; 
$amount = $row['amount']; 
$trans_id = $row['trans_id']; 
$time_paid = $row['time_paid']; 

$pdf->SetY($y_axis); 
$pdf->SetX(25); 
$pdf->Cell(30,6,$name,1,0,'L',1); 
$pdf->Cell(100,6,$amount,1,0,'L',1); 
$pdf->Cell(30,6,$trans_id,1,0,'R',1); 
$pdf->Cell(30,6,$time_paid,1,0,'R',1); 

//Go to next row 
$y_axis = $y_axis + $row_height; 
$i = $i + 1; 
} 

mysql_close($link); 

//Send file 
$pdf->Output(); 
?> 
+0

それは言及する。解析エラーは、あなたが間違っていたことを意味します。かっこ、ドル記号、セミコロンなどを忘れてしまった。 SOはデバッグサービスではないため、このような質問はトピック外と見なされます。 [ヘルプ]の[ask]をお読みください。オフトピックとしてマークされている - デバッグヘルプを探しています。 – Pred

答えて

0

あなたは上記の行にセミコロン;を見逃していると、このエラーは、ほとんどoccures。以下を参照してください:線の上

$y_axis = $y_axis + $row_height; 

あなたは

$pdf->Cell(30,6,'trans_id',1,0,'R',1); 
$pdf->Cell(30,6,'time_paid',1,0,'R',1) <-- missing ; here 

を逃すことはあるべき;をセミコロンしている:あなたは、エラーメッセージを読んで、部品をチェックすることにより、この問題を解決

$pdf->Cell(30,6,'trans_id',1,0,'R',1); 
$pdf->Cell(30,6,'time_paid',1,0,'R',1); 
関連する問題