How to position two tables on the same line with PHP FPDF?

0

I am trying to create two tables on the same line but I can not get it, I would appreciate some help.

_________________________     _________________________
Lado Izquierdo | Cumple        Lado Derecho | Cumple          
_________________________     _________________________
  Lado1        |  Si           Lado1        |  Si          
  Lado2        |  No           Lado2        |  Si
  Lado3        |  Si           Lado3        |  Si
  Lado4        |  Si           Lado4        |  Si
_________________________     _________________________

 _________________________    
Lado Frente    | Cumple            
__________________________
  Lado1        |  Si                 
  Lado2        |  No          
  Lado3        |  Si      
  Lado4        |  Si      
_________________________

My code is as follows, I try to position the table on the right side passing the position in X and Y

   <?php
require('/../../_FPDF/fpdf.php');

class PDF extends FPDF
{
    function BasicTable($header, $data, $x = 0, $y = 0)
    {
        // Cabecera
        if ($x > 0 and $y > 0) {
            $this->SetXY($x , $y);
        }
        foreach ($header as $col)
            $this->Cell(40, 7, $col, 1);
        $this->Ln();

        // Datos
        foreach ($data as $row) {
            foreach ($row as $col) {
                if ($x > 0 and $y > 0) {
                    $this->SetXY($x + 10 , $y + 10);
                }
                $this->Cell(40, 6, $col, 1);
            }
            $this->Ln();
        }
    }
}

$pdf = new PDF();
$pdf->SetFont('Arial', '', 14);
$pdf->AddPage();

//TABLA 1
$header = array('Lado Izquierdo', 'Cumple');
$data = [];
for ($index = 0; $index < 13; $index++) {
    array_push($data, array("izquierdo" . $index, 'valor' . $index));
}
$pdf->BasicTable($header, $data);
$pdf->Ln(5);

//TABLA 2
$header = array('Lado Derecho', 'Cumple');
$data = [];
for ($index = 0; $index < 5; $index++) {
    array_push($data, array("derecho" . $index, 'valor' . $index));
}
$pdf->BasicTable($header, $data , 115 , 10 );
$pdf->Ln(5);

//TABLA 3
$header = array('Lado Frente', 'Cumple');
$data = [];
for ($index = 0; $index < 13; $index++) {
    array_push($data, array("frente" . $index, 'valor' . $index));
}
$pdf->BasicTable($header, $data);


$pdf->Output();
?>
    
asked by Alexander Morales 18.08.2017 в 18:40
source

1 answer

0

Modifying the SetXY positions ($ x, $ y) got the report you need.

class PDF extends FPDF {
    function BasicTable($header, $data, $x = 0, $y = 0) {

		$this->SetXY($x , $y);
		
		// Header
		foreach($header as $col)
			$this->Cell(40 ,7,$col,1);
		$this->Ln();
		
		// Data
		$i = 7;
		$this->SetXY($x , $y + $i);
		foreach($data as $row){
			foreach($row as $col){
				//$this->SetXY($x , $y + $i);
				$this->Cell(40 ,6,$col,1);
				
			}
			$i= $i + 6 ;  // incremento el valor de la columna
			$this->SetXY($x , $y + $i);		
		  //$this->Ln();
		}
	}
}

$pdf = new PDF();
$pdf->SetFont('Arial', '', 14);
$pdf->AddPage();



//TABLA 1
$header = array('Lado Izquierdo', 'Cumple');
$data = [];
for ($index = 0; $index < 13; $index++) {
    array_push($data, array("izquierdo" . $index, 'valor' . $index));
}
$pdf->BasicTable($header, $data, 10, 10);
//pdf->Ln(5);



//TABLA 2
$header = array('Lado Derecho', 'Cumple');
$data1 = [];
for ($index = 0; $index < 5; $index++) {
    array_push($data1, array("derecho" . $index, 'valor' . $index));
}
$pdf->BasicTable($header, $data1 , 100,10  );
$pdf->Ln(5);


//TABLA 3
$header = array('Lado Frente', 'Cumple');
$data = [];
for ($index = 0; $index < 13; $index++) {
    array_push($data, array("frente" . $index, 'valor' . $index));
}

$pdf->BasicTable($header, $data, 10, 110);


$pdf->Output();
    
answered by 19.08.2017 / 03:35
source