0
votes

I'm trying to output mysql data to a pdf using ezpdf. I have successfully generated the first part of my report but the second part a lot of columns and of course won't across the page. The diagram below will probably explain what I'm trying to do.

Example of the current layout:


|---HEADER--|---HEADER2--|---HEADER3--|---HEADER4--|---HEADER5--|

| USERNAME1 | DATAFIELD1 | DATAFIELD2 | DATAFIELD3 | DATAFIELD3 |

| USERNAME2 | DATAFIELD1 | DATAFIELD2 | DATAFIELD3 | DATAFIELD3 |

| USERNAME3 | DATAFIELD1 | DATAFIELD2 | DATAFIELD3 | DATAFIELD3 |


Example of what I'm trying to accomplish:


|----HEADER1---|---HEADER2---|

| USERNAME1 | DATAFIELD1 |

|---HEADER3---|---HEADER4---|---HEADER5---|

| DATAFIELD2 | DATAFIELD3 | DATAFIELD4 |


|----HEADER1---|---HEADER2---|

| USERNAME2 | DATAFIELD1 |

|---HEADER3---|---HEADER4---|---HEADER5---|

| DATAFIELD2 | DATAFIELD3 | DATAFIELD4 |


|----HEADER1---|---HEADER2---|

| USERNAME3 | DATAFIELD1 |

|---HEADER3---|---HEADER4---|---HEADER5---|

| DATAFIELD2 | DATAFIELD3 | DATAFIELD4 |


I hope that makes sense. If any one can help it would be very much appreciated.

Below is my test code

test code

3

3 Answers

0
votes

Actually,if you are not mantaining old code, i advise you use TCPDF to generate PDF from php which offers a lot of functionality. for example converting html to PDF code withouth problems.

In you case you could create html tables and then convert them like in this example

EDIT - in TCPDF you have to be very careful on how you markup your tables: from your link i see an error in your markup. the table you are trying to create should be like this:

$tbl = '
<table border="1" cellpadding="2" cellspacing="2">
<thead>
 <tr style="background-color:#FFFF00;color:#0000FF;">
  <td align="center"><b>USERNAME</b></td>
  <td align="center"><b>LASTNAME</b></td>
  <td align="center"><b>FIRSTNAME</b></td>
 </tr>
</thead>
<tbody>
  <tr style="background-color:#FF0000;color:#FFFF00;">
     <td align="left">' .$username. '</td>
     <td></td>
     <td></td>
  </tr>
</tbody>
</table>
';
0
votes

ok I fixed the error and got the loop working. For some reason though it's cutting off the first row of data.

    $tbl = '
<table border="1" cellpadding="1" cellspacing="2">
 <tr style="background-color:#666666;color:#FFFFFF;">
  <td align="center"><b>TITLE 1 HERE</b></td>
  <td align="center"><b>TITLE 2 HERE</b></td>
  <td align="center"><b>TITLE 3 HERE</b></td>
 </tr>';
while($row = mysql_fetch_array($Recordset1))
  {

$tbl = $tbl .'  <tr style="background-color:#000066;color:#FFFFFF;">
  <td align="left">Name: '.$row[lastname].', '.$row[firstname].'</td>
 </tr>'
    .'  <tr style="background-color:#CCCCCC;color:#000000;">
  <td align="left">'.ValLesson1.'</td> 
  <td align="left">'.ValLesson2.'</td>
  <td align="left">'.ValLesson3.'</td>
  </tr>'
 .'<tr style="background-color:#FFFFFF;color:#000000;">
 <td align="left">'.$row[most_valuable_lesson].'</td>
 <td align="left">'.$row[second_valuable_lesson].'</td>
 <td align="left">'.$row[third_valuable_lesson].'</td>
 </tr>'
    .'  <tr style="background-color:#CCCCCC;color:#000000;">
  <td align="left">'.CourseStrengths.'</td>
  <td align="left">'.CourseWeakness.'</td>
 </tr>'
 .'<tr style="background-color:#FFFFFF;color:#000000;">
 <td align="left">'.$row[course_strength].'</td>
 <td align="left">'.$row[course_weakness].'</td>
 </tr>'
; }
$tbl = $tbl . '</table>'; 

$pdf->writeHTML($tbl, true, false, false, false, '');

any ideas?

0
votes

In the example code that you posted, you are calling mysql_fetch_assoc($Recordset1) before the loop using mysql_fetch_array($Recordset1), so the loop will have missed the first result. If you are doing the same in your other code then this will be the problem.