2016-06-17 2 views
-1

pdf 형식의 데이터베이스 내용을 출력해야하는이 PHP 스크립트가 있습니다. 구문 분석 오류, 예기치 않은 '$ y_axis'(T_VARIABLE) .. "오류가 발생했습니다."이 줄
어떻게 해결하나요? // 다음 행으로 이동 $ 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. 아래를 참조

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

누락이 ;을 세미콜론으로 한

$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); 
관련 문제