I have a php file that creates a pdf from a mysql query using fpdf. On the original input to the form is a dynamic drop down with four categories. Category 1 the form displays questions Categoryquestion1,Categoryquestion2, etc. and writes to the db. I am pulling one record at a time in the query and there will always be some blank fields (if they choose Category1 the fields for Category 2,3, etc will be blank. In my pdf, I show the question and the answer. If there a way to not show the question and answer if the value returned in the query is blank?
Here is some code that might make it clearer:
$result = mysql_query("SELECT
title
,abstr
,presenters
,keywords
,comments
,outcomes
,CategorySelection
,research3
,research4
,innovation3
,innovation4
,references
,organization
FROM database
.table
WHERE id
='$id' LIMIT 1;");
$data = mysql_fetch_assoc($result);
$id = $data['id'];
$title = $data['title'];
$abstract = $data['abstr'];
$presenters =$data['presenters'];
$outcomes =$data['outcomes'];
$keywords = $data['keywords'];
$CategorySelection =$data['CategorySelection']; //if not blank
$research3 =$data['research3']; //if not blank
$research4 =$data['research4']; //if not blank
$innovation3 =$data['innovation3']; //if not blank
$innovation4 =$data['innovation4']; //if not blank
$references =$data['references']; //if not blank
$organization =$data['organization']; //if not blank
$comments = $data['comments'];
//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>
In this example, if the value for CategorySelection is research and those fields had contents, the question above and the data for Research3 an Research4 would go into the pdf. If they chose Innovation, the questions and answers for innovation3 and innovation4 would go in the pdf. In some cases, they don't even have to choose a Category, so it really needs to be based on empty fields returned in the query. I hope I explained this correctly.