2014-04-09 2 views
0

fpdf를 사용하여 mysql 쿼리에서 pdf를 생성하는 PHP 파일이 있습니다. 양식에 대한 원래 입력에는 네 가지 카테고리가있는 동적 드롭 다운이 있습니다. 범주 1은 질문 Categoryquestion1, Categoryquestion2 등을 표시하고 db에 씁니다. 쿼리에서 한 번에 하나의 레코드를 당기고 거기에 항상 빈 필드가있을 것입니다. (범주 1을 선택하면 범주 2,3 등의 필드는 비어 있습니다.) 내 PDF에서는 질문과 대답을 표시합니다. ? 질문을 표시하고 쿼리에서 반환 값이 비어 있으면 대답 을 여기에서하지 수있는 방법이 명확하게 수있는 몇 가지 코드가 : $result = mysql_query("SELECT title, abstr, presenters, keywords, comments, outcomes, CategorySelection, research3, research4, database FROM innovation3, innovation4, references, organizationtable WHERE id = '$ 아이디'LIMIT 1]. "); $ 데이터 = mysql_fetc h_assoc ($ 결과); $ id = $ data [ 'id']; $ title = $ data [ 'title']; $ 초록 = $ 데이터 [ 'abstr']; $ presenters = $ data [ '발표자']; $ outcomes = $ data [ 'outcomes']; $ keywords = $ data [ 'keywords']; $ CategorySelection = $ data [ 'CategorySelection']; // 공백이 아닌 경우 $ research3 = $ data [ 'research3']; // 공백이 아닌 경우 $ research4 = $ data [ 'research4']; // 공백이 아닌 경우 $ innovation3 = $ data [ 'innovation3']; // 공백이 아닌 경우 $ innovation4 = $ data [ 'innovation4']; // 공백이 아닌 경우 $ references = $ data [ 'references']; // 공백이 아닌 경우 $ organization = $ data [ 'organization']; // 공백이 아닌 경우 $ comments = $ data [ 'comments']; 이 예에서 mysql 쿼리에서 fpdf 생성 - pdf에 빈 값을 추가하지 않는 방법

 //create pdf 
require ('/opt/webapps/fpdf/fpdf.php'); 

$pdf=new FPDF('P', 'mm', 'Letter'); 
$pdf->AddPage('P'); 
$pdf->SetFont('Arial','B',12); 
$pdf->Write(5,$title); 
$pdf->SetXY(10,25); 
$pdf->Cell(20,10,"Abstract:",10,10); 
$pdf->SetFont('Arial','',12); 
$pdf->Write(5,$abstract); 
$pdf->SetXY(10,60); 
$pdf->SetFont('Arial','B',12); 
$pdf->Cell(20,20,"Presenters:",10,10); 
$pdf->SetFont('Arial','',12); 
$pdf->Write(5,$presenters); 
$pdf->SetFont('Arial','B',12); 
$pdf->Cell(20,10,"Outcomes:",10,10); 
$pdf->SetFont('Arial','',12); 
$pdf->Write(5,$outcomes); 
$pdf->Cell(20,10,"Category: $CategorySelection",10,10); 
$pdf->SetFont('Arial','B',12); 
$pdf->MultiCell(180,6,"Indicate your teaching and learning project. ",10,10); 
    $pdf->SetFont('Arial','',12); 
$pdf->Write(5,$research3); 
$pdf->SetFont('Arial','B',12); 
$pdf->MultiCell(180,6,"If your project involved a particular course, briefly describe the course, its students, and its place in the curriculum.",10,10); 
    $pdf->SetFont('Arial','',12); 
$pdf->Write(5,$research4); 

$pdf->SetFont('Arial','B',12); 
$pdf->MultiCell(180,6,"Describe the planned innovation addressed in your paper. ",10,10); 
    $pdf->SetFont('Arial','',12); 
$pdf->Write(5,$innovation3); 
$pdf->SetFont('Arial','B',12); 
$pdf->MultiCell(180,6,"If your innovation involves a particular course, briefly describe the course, its students, and its place in the curriculum.",10,10); 
    $pdf->SetFont('Arial','',12); 
$pdf->Write(5,$innovation4Raw); 
$pdf->SetFont('Arial','B',12); 
$pdf->MultiCell(180,6,"How is your innovation different from ones that others have tried?",10,10); 
    $pdf->SetFont('Arial','',12); 
$pdf->Write(5,$innovation5); 
</code> 

, CategorySelection의 값이 연구는 그 필드 내용 Research4은 PDF로 갈 것입니다 위의 질문 Research3에 대한 데이터가 있다면. 그들이 혁신을 선택했다면, innovation3와 innovation4에 대한 질의 응답은 pdf로 갈 것입니다. 어떤 경우에는 범주를 선택하지 않아도되므로 실제로 쿼리에서 반환 된 빈 필드를 기반으로해야합니다. 나는 이것을 정확하게 설명했으면한다.

답변

1

저는 이 아닙니다.은 질문에 대한 데이터가없는 곳에 빈 줄을 남기고 싶습니다.

예를 들어, "귀하의 논문에서 제시 한 계획된 혁신을 설명하십시오"라는 질문에 대한 답이없는 경우 빈 줄을 남기지 않고 질문과 답변을 건너 뛰고 싶습니다. 이 작업을 수행합니다 :

if($innovation3) 
{ 
    $pdf->SetFont('Arial','B',12); 
    $pdf->Cell(180,6,"Describe the planned innovation addressed in your paper. ",0,1); 
    $pdf->SetFont('Arial','',12); 
    $pdf->Cell(180,6,$innovation3, 0, 1); 
} 

여기에서 차이가 나는 Cell 대신 MultiCellWrite를 사용하고 있다는 점이다.

Write 어디서나 텍스트의 끝에 커서를 둡니다. Cell 메소드의 마지막 인수는 커서를 아래쪽으로 이동시켜 다음 행의 시작 부분으로 이동하므로 여기에 계속 쓸 수 있습니다. 이 방법으로 FPDF는 다음 텍스트를 쓸 위치를 추적합니다.

+0

감사합니다. Kryten - 그게 내가 원하는 것입니다. 나는 집으로 오는 길에 명백한 것의 출현을 가지고 있었고 조건부 진술을 생각했다. 나는 그것이 나에게 너무 일찍 일어나지 않았다는 것을 믿을 수 없다. 그렇게 명백하고 쉬운 일이다! 다시 한 번 감사드립니다! –

관련 문제