Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

multi columns with fpdf

Posted on 2009-03-31
2
Medium Priority
?
5,621 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

971 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