Hi
I am generating 6 tables in pdf using fpdf in php but i am getting each table in a seperate page even if table contains only one row can you help me in this issue

function


function BuildTable5($header5,$data5) 
            {   
            $this->SetFillColor(255,255,255);
            $this->SetTextColor(0);
            $this->SetDrawColor(0);
            $this->SetLineWidth(.3);
            $this->SetFont('','B');
//Header
            $w=array(30,50,20,20);
            $this->SetFont('Arial','B',7);
            for($i=0;$i<count($header5);$i++)
                $this->Cell($w[$i],7,$header5[$i],1,0,'C',true);
                $this->Ln();
//Color and font restoration
                $this->SetFillColor(224,235,255);
                $this->SetTextColor(0);
                $this->SetFont('');
//Data
                $fill=false;
                $i = 0;
                $x0=$x = $this->GetX();
                $y = $this->GetY();
 //GLOBAL $y;
                foreach($data5 as $row)
                {
                for ($i=0; $i<6; $i++) //Avoid very lengthy texts
                {
                    $row[$i]=substr($row[$i],0,160);
                }
                $yH=11; //height of the row
//Issue a page break first if needed
                $this->SetXY($x, $y);
                $this->Cell($w[0], $yH, "", 'LRB',0,'',$fill);
                $this->SetXY($x, $y);
                $this->MultiCell($w[0],6,$row[0],0,'L');

                $this->SetXY($x + $w[0], $y);
                $this->Cell($w[1], $yH, "", 'LRB',0,'',$fill);
                $this->SetXY($x + $w[0], $y);
                $this->MultiCell($w[1],5,$row[1],0,'L');

                $x =$x+$w[0];
                $this->SetXY($x + $w[1], $y);
                $this->Cell($w[2], $yH, "", 'LRB',0,'',$fill);
                $this->SetXY($x + $w[1], $y);
                $this->MultiCell($w[2],5,$row[2],0,'L');

                $x =$x+$w[1];
                $this->SetXY($x + $w[2], $y);
                $this->Cell($w[3], $yH, "", 'LRB',0,'',$fill);
                $this->SetXY($x + $w[2], $y);
                $this->MultiCell($w[3],6,$row[3],0,'L');

                $y=$y+$yH; //move to next row
                $x=$x0; //start from firt column
                }
            }



            $j=0;                                                                            
$i=1;
if (count($data5)!=0)
{
    foreach ($data5 as $row)
    {
        $pagedata[$j]=$row;
        if ((count($data5)<18 && $i== count($data5)))
        {
            $pdf->BuildTable5($header5,$pagedata);
            $j=0;
            $pagedata="";
        }
        if (($i%18)==0)
        {
            if($i!=18)
            {
                $pdf->AddPage();
            }
            $pdf->BuildTable5($header5,$pagedata);
            $j=0;
            $pagedata="";
        }
        if($i==count($data5) && ($i%18) !=0 && count($data5)>18)
        {
            $pdf->AddPage();
            $pdf->BuildTable5($header5,$pagedata);
            $j=0;
            $pagedata="";
        }
    $i++;
    $j++;
    }
}

In your example above, try removing lines 79 to 82.

if($i!=18)
{
    $pdf->AddPage();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.