Jump to content

Archived

This topic is now archived and is closed to further replies.

nerd99

echo out columns in pdf timetable

Recommended Posts

Hi there,

 

I'm stuck!

 

I am using tcpdf to create a list of timetables as a pdf. I have no trouble achieving the pdf. What I am having trouble with getting the loops to echo out as separate columns instead of rows.

 

Here is the scenario: I have a database called 'timetables'. Each row contains information including Tutor's name, School, Lesson time, Student's name. I would like the above row to appear on the page in one column and the next row to appear in the next column in the pdf.

 

Is this making sense?

 

For example: Under the title 'Monday', would have Tutor 1 with times and students listed below, then directly next to that would be Tutor 2 with times and students listed below.

 

Here is my very poor attempt to get the results. I can get the columns happening but it just prints the same tutor's name in both columns.

<?php
//============================================================+
// File name   : example_017.php
// Begin       : 2008-03-04
// Last Update : 2010-05-20
//
// Description : Example 017 for TCPDF class
//               Two independent columns with MultiCell
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
* Creates an example PDF TEST document using TCPDF
* @package com.tecnick.tcpdf
* @abstract TCPDF - Example: Two independent columns with MultiCell
* @author Nicola Asuni
* @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
* @link http://tcpdf.org
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @since 2008-03-04
*/

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 017');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 017', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 20);

// add a page
$pdf->AddPage();

$pdf->Write(0, 'Example of independent Multicell() columns', '', 0, 'L', true, 0, false, false, 0);

$pdf->Ln(5);

$pdf->SetFont('times', '', 12);

require_once('../../includes/connection.php');

$result = mysqli_query($connection,"SELECT * FROM timetables WHERE school='schoolname' AND day='Wednesday' ")
or die(mysqli_error($connection));

while($row = mysqli_fetch_array($result)) {

//get all rows you want from the tutor_invoices table

        $id = $row['id'];
        $school = $row['school'];
        $day = $row['day'];
     
}

$pdf->Ln(6.6);

//light blue w black text
$pdf->SetFillColor(177, 223, 243);
$pdf->SetTextColor(0, 0, 0, 100);
// Timetable Details)
$pdf->MultiCell(200, 5, $day, 1, 'C', 1, 0, 5, '', true);
$pdf->Ln(7.35);

$result = mysqli_query($connection,"SELECT * FROM timetables WHERE school='schoolname' AND day='Wednesday' ")
or die(mysqli_error($connection));

while($row = mysqli_fetch_array($result)) {

//get all rows you want from the tutor_invoices table

        $tutor = $row['tutor'];
        
  
}
        
// create columns content
$left_column = $tutor."\n";

$right_column = $tutor."\n";

// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)

// set color for background
$pdf->SetFillColor(255, 255, 200);

// set color for text
$pdf->SetTextColor(0, 63, 127);

// write the first column
$pdf->MultiCell(80, 0, $left_column, 1, 'J', 1, 0, '', '', true, 0, false, true, 0);

// set color for background
$pdf->SetFillColor(215, 235, 255);

// set color for text
$pdf->SetTextColor(127, 31, 0);

// write the second column
$pdf->MultiCell(80, 0, $right_column, 1, 'J', 1, 1, '', '', true, 0, false, true, 0);

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_017.pdf', 'I');

//============================================================+
// END OF FILE                                                
//============================================================+
?>

 

Does anybody know how to achieve this?

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.