Solved

multi columns with fpdf

Posted on 2009-03-31
2
4,958 Views
Last Modified: 2012-08-14
Hi

been trying to figure the code below out it uses fpdf from here http://www.fpdf.org/
to convert a php page to pdf


at the minute it gets the results from the database and puts it into two columns like this below

info 1            info 7
info 2            info 8
info 3            info 9
info 4            info 10
info 5            info 11
info 6            info 12
                      info 13
                      info 14
                      info 15

how would i get it to go into a third column when it gets another 6 results




$pdf->SetXY(100,150);
$y_axis = 200;
$y2_axis = 0;
 
$sql = "select listingsdbelements_field_value from default_en_listingsdbelements where listingsdbelements_field_name = 'home_features' and listingsdb_id = '$listingID' limit 1"; 
$res = mysql_query($sql, $connection) or die(mysql_error());
 
//initialize counter
$i = 0;
 
while ($row = mysql_fetch_array($res)) {
$feature_index_list = explode("||", $row[0]);
sort($feature_index_list);
foreach($feature_index_list as $feature_list_item)
 
// prints 6 results then goes to the next cell
if ($i < 6) {
	$pdf->SetY($y_axis);
	$pdf->SetX(90);
 
	$pdf->Cell(20,4,$feature_list_item,0,1,L,'');
 
	//Go to next row
 
	$y_axis = $y_axis + 3;
	$i = $i+1;
	}
 
 
	else {
	$inity_axis = 200;
	$pdf->SetY($inity_axis+$y2_axis);
	$pdf->SetX(135);
 
 
 
	$pdf->Cell(20,4,$feature_list_item,0,1,L,'');
	$y2_axis = $y2_axis + 3;
 
	$i = $i+1;
 
 
 
	}
 
}

Open in new window

0
Comment
Question by:peter2001
2 Comments
 
LVL 10

Accepted Solution

by:
ollyatstithians earned 250 total points
ID: 24027172
Solution 1:
Have a look in the FPDF tutorials at the multi-column tutorial (http://www.fpdf.org/en/tutorial/tuto4.htm).
This is for a two columns, but we want 3, so to add a third one we need to alter the code a little. First we need to stop it making a new page after column 2. Alter the AcceptPageBreak() method by changing the line
  if($this->col<2)
to
  if($this->col<3)

Now we need to adjust the column widths and positions. Look at the method SetCol(). Change the line
  $x=10+$col*65;
to
  $x=10+$col*43;
That fixes the positions, but the widths are still adrift. This is set in ChapterBody(). Change this line
  $this->MultiCell(60,5,$txt);
to
  $this->MultiCell(40,5,$txt);

You should now have a fluid 3 column layout.

Solution 2:
Your code only detects if the list is less than 7 long (0 to 6). It then fails to column 2. We need to add a condition for column 3. Before your else block insert an elseif:

       elseif($i<12) {
        $inity_axis = 200;
        $pdf->SetY($inity_axis+$y2_axis);
        $pdf->SetX(202);     // Change the value here to adjust the position of col 3
        $pdf->Cell(20,4,$feature_list_item,0,1,L,'');
        $y2_axis = $y2_axis + 3;
        $i = $i+1;
       }

Repeat for each subsequent column.

Olly.
0
 
LVL 1

Author Comment

by:peter2001
ID: 24027436
Thats perfect that helps me understand it and your solution 2 works just as i need it to.

Thank you very much for your help

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Making API calls from hashed passwords 26 54
php extract($_REQUEST) 5 53
two ways encryption with php 3 28
How to submit record from external php form to a Sharepoint list? 5 34
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question