Solved

multi columns with fpdf

Posted on 2009-03-31
2
5,298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
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 …

623 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