Solved

multi columns with fpdf

Posted on 2009-03-31
2
4,806 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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now