Search code examples
phppdfphpmyadmintcpdffpdf

How to have multicolumn in a pdf through php and fpdf


I am having some trouble with php and fpdf.

I have to make a report in pdf format through fpdf and php in which i want to show students a teacher is teaching.

What i want is that the fpdf should create a page with multiple column with same field.

link of the pic: http://i1267.photobucket.com/albums/jj552/ThePerfectH/abc.png

in this image as you can see, i want the data till 30 in one column and after that it should move in different column in one page.

Example Code:

$result=mysql_query("select p.p_sname as pap from sgm, students st
    left join sps on st.studentid=sps.studentid
    left join papers p on p.p_id=sps.paperid where p.type='optional' and
    sgm.studentid=st.studentid and sgm.groupid=3 and st.course=3 and
    st.status='Regular' order by name");
    if($result === FALSE)
{
die(mysql_error()); // better error handling
}
$i=0;
$max=30;
$s=1;
$row_height = 6;
$y_axis = 33 + $row_height;
while($row = mysql_fetch_array($result))
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
    $y_axis= 33 + $row_height;
    $pdf->SetX(80);
    $pdf->SetTextColor(153,0,102);
    $pdf->SetFont('Arial','',10);
        //print column titles for the current page
    $pdf->SetY(33);
    $pdf->SetX(80);
    $pdf->Cell(20,6,'S No.',1,0,'C',1);
    $pdf->SetY($y_axis);
    $pdf->SetX(80);
    $pdf->Cell(20,6,$s,1,0,'C',1);
    $y_axis = $y_axis + $row_height;
        $i = $i + 1;
    $s=$s+1;


}

        $rollno=$row['rollno'];
    $name=$row['name'];
    $cat=$row['cat'];
    $pap=$row['pap'];
    $pdf->SetY($y_axis);
    $pdf->SetX(48);
    $pdf->SetFont('Arial','',10);
    $pdf->Cell(20,6,$s,1,0,'C',1);
    //Go to next row
    $s=$s+1;
    $y_axis = $y_axis + $row_height;

        $i = $i + 1;    }       

As you can see in the pic, this is leading to overlapping of my row after creating just one new column.

Can any one help.


Solution

  • I have done it by changing SetX to x_axis and as it reaches 30 it addes to x_axis