Als ik naar hun voorbeelden kijk, vooral voorbeeld 11 spreekt mij enorm aan, is het maken van een table met om en om kleuren erin.
Zij gebruiken in hun functie deze code ervoor.:
// Colored table
public function ColoredTable1($header1,$data1) {
// Colors, line width and bold font
$this->SetFillColor(255, 0, 0);
$this->SetTextColor(255);
$this->SetDrawColor(128, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$w = array(15, 15, 150); //kolom 1 breedte,kolom 2 breedte,kolom 3 breedte,kolom 4 breedte,kolom 5 breedte, enz.
$num_headers = count($header1);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header1[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(224, 235, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
foreach($data1 as $row) {
$this->Cell($w[0], 6, $row[0], 'LR', 0, 'C', $fill); //L=links, R=Rechts, C=Center
$this->Cell($w[1], 6, $row[1], 'LR', 0, 'C', $fill); //L=links, R=Rechts, C=Center
$this->Cell($w[2], 6, $row[2], 'LR', 0, 'L', $fill); //L=links, R=Rechts, C=Center
//$this->Cell($w[3], 6, number_format($row[3]), 'LR', 0, 'R', $fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w), 0, '', 'T'); //Afsluit lijn van table
}Iets verder gebruiken ze dan in hun code.:
// set font
$pdf->SetFont('helvetica', '', 8);
// add a page
$pdf->AddPage();
//plaats een test text
$pdf->Write(0, 'test 1', '', 0, '', true, 0, false, false, 0);
// column1 titles
$header = array('Van', 'Tot', 'Opmerking');
// data loading
$data = $pdf->LoadData('data/table_data_demo.txt');
// print colored table
$pdf->ColoredTable($header, $data); Dit is voor mij de ideale uitvoer wat ik in de pdf wil zien.
Echter nu is mijn vraag, heeft dit iemand ook al een getest maar met gebruik van gegevens uit sql ipv die text file?
Ik heb al verschillende codes geprobeerd, maar niks werkt.
Ik kom nu alleen met een werkende uit zonder gekleurde mooie balken met deze code.:
$tbl_header = '<table border="1">';
$tbl_footer = '</table>';
$tbl ='';
$con=mysqli_connect("localhost","root","xxxxx","xxxxxxx");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM metingen LIMIT 10");
while($row = mysqli_fetch_array($result))
{
$id = $row['Id'];
$key = $row['Orders'];
$key1 = $row['Batch_Nr'];
$tbl .= '<tr><td>' . $id . '</td><td>' . $key . '</td><td>' . $key1 . '</td></tr>';
}
// Print text using writeHTMLCell()
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
// close and output PDF document
$pdf->Output('Dienstrapport', 'I');