Page 1 of 1

Weird class problem I think

Posted: Sat Aug 16, 2003 12:16 am
by feras
ok guys. I am using fpdf (http://www.fpdf.org) to convert info from a mysql database to the pdf file.

This is my code:

Code: Select all

$temp = mysql_query("SELECT * FROM images WHERE id=$id") or die("<br>" . mysql_errno().": ".mysql_error()."<br>"); //check if query successful, if not print error
	$imageOverall = mysql_fetch_assoc($temp);
	$image_Filename = $imageOverall&#1111;'filename'];
	$image_Width = $imageOverall&#1111;'width'];
	$image_Height = $imageOverall&#1111;'height'];
//	print "$image, $image_Filename, $image_Width, $image_Height";
	
	$temp = mysql_query("SELECT * FROM vehicles WHERE id=$id") or die("<br>" . mysql_errno().": ".mysql_error()."<br>"); //check if query successful, if not print error
	$vehicleOverall = mysql_fetch_assoc($temp);
	$description = $vehicleOverall&#1111;'description'];
	$nadaPrice = $vehicleOverall&#1111;'price'];
	$model = $vehicleOverall&#1111;'model'];
	$mileage = $vehicleOverall&#1111;'miles'];
	 $vin = $vehicleOverall&#1111;'vin'];
//	$vin="99999";
//	print "$description, $nadaPrice, $model, $mileage, $vin";
	$temp = mysql_query("SELECT * FROM saleprice WHERE id=$id") or die("<br>" . mysql_errno().": ".mysql_error()."<br>"); //check if query successful, if not print error
	$salepriceOverall = mysql_fetch_assoc($temp);
	$salePrice = $salepriceOverall&#1111;'price'];
	
	$query = "SELECT name FROM features WHERE ID=$id;";
	$temp = mysql_query($query, $link) or die("<br>" . mysql_errno().": ".mysql_error()."<br>"); //check if query successful, if not print error
	$features = mysql_fetch_assoc($temp);

$result = mysql_query("SELECT * FROM features_lookup WHERE vid='$id' AND fid='$oid'"); 
if (mysql_num_rows($result)) &#123; 
	$features = mysql_fetch_assoc($result);
	$fid=$features&#1111;'fid'];
$result2 = mysql_query("SELECT * FROM features WHERE id='$fid'"); 
	$total_features="";
	while($features = mysql_fetch_assoc($result))&#123;
		$total_features = $total_features." ";
		$total_features = $total_features.$features;
		&#125;
&#125;


	
define('FPDF_FONTPATH','font/');
require('fpdf.php');



class PDF extends FPDF
&#123;
//Page header
function Header() 
&#123;

	global $vin;	
	
	$this->Rect(5, 5, 200, 280); 
	

//    $this->Image($image_Filename,0,0,$image_Width,$image_Height);


       

    //Arial bold 15
    $this->SetFont('Arial','B',15);
    
    
      //Move to the right
    $this->Cell(125);
        $this->Ln(5);
       //Move to the right
    $this->Cell(125);
 $this->Cell(60,5,'Dealership',0,0,'1');
        $this->Ln(5);
                //Arial bold 15
    $this->SetFont('Arial','',15);

      //Move to the right
    $this->Cell(125);
  $this->Cell(60,5,'100 My Street  ',0,0,'1');
        $this->Ln(5);
     //Move to the right
    $this->Cell(125);
   $this->Cell(60,5,'City ST, 28033  ',0,0,'1');
        $this->Ln(5);
	
	 //Move to the right
    $this->Cell(125);
   $this->Cell(60,5,$number,0,0,'1');
        $this->Ln(5);

    //Line break
    $this->Ln(15);
        //Title
    $this->Cell(65,4,'Some Dynamic Info Here!',0,0,'1');
  
     //Move to the right
    $this->Cell(10);
            //Arial bold 15
    $this->SetFont('Arial','b',13);

        //Title
    $this->Cell(140,4,$model,0,0,'1');
    
    
    
        //Line break
    $this->Ln(6);

     //Move to the right
    $this->Cell(75);
    

         //Arial bold 15
    $this->SetFont('Arial','',13);
  
   
    
        //Title
$this->Cell(160,4,'VIN:'.$vin ,0,0,'1'); 
    
    
    
   
    
        //Line break
    $this->Ln(6);

     //Move to the right
    $this->Cell(75);
    
           //Title
$this->Cell(160,4,'Miles:'.$mileage ,0,0,'1');
            
            
                 //Move to the right
    $this->Cell(90);

        //Title
    $this->Cell(160,4,'ad',0,0,'1');
    
    

    
 
    
    
        //Line break
    $this->Ln(6);


             //Arial bold 15
    $this->SetFont('Arial','b',12);

   
        //Title
    $this->Cell(200,4,"Vehicle Description: $description",0,0,'1');
      $this->SetFont('Arial','',12);
              //Line break
    $this->Ln(6);


   
             //Arial bold 15
    $this->SetFont('Arial','',12);

    
        //Title
    $this->Write(5,'I throoughly enjoyed this car, it is a fun too car too drive and you know I would never sell a car that I didnt want in my own collection');
	        //Line break
    $this->Ln(10);

    
    
    
    
             //Arial bold 15
    $this->SetFont('Arial','b',12);

   
        //Title
    $this->Cell(200,4,"Features:$total_features",0,0,'1');
     $this->SetFont('Arial','',12);
              //Line break
    $this->Ln(6);

 
        //Title
    $this->Write(5,'This car is cool, I have ridden in it for many years, and always enjoy a good old fashioned ride in it. I would never sell anything that I wouldnt want in my own collection! and thats the truth!');
        //Line break
    $this->Ln(14);

     //Move to the right
    $this->Cell(50);
                 //Arial bold 15
    $this->SetFont('Arial','',18);


  
    
   
        //Title
$this->Cell(160,4,"NADA:$nadaPrice" ,0,0,'1');

        //Line break
    $this->Ln(5);

     //Move to the right
    $this->Cell(50);
                 //Arial bold 15
    $this->SetFont('Arial','',18);


   
        //Title
$this->Cell(160,4,"Our Prices: $salePrice" ,0,0,'1');
    
    


    
            //Line break
    $this->Ln(12);
                 //Arial bold 15
    $this->SetFont('Arial','',9);

   
        //Title
    $this->Cell(195,4,'Terms and condition can go here.',1,0,'1');

	



    
    
&#125;

&#125;

//Instanciation of inherited class
	
$pdf=new PDF();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->Output();







?>

Now, all of the variables that I set up top (such as $vin) are actually set and do contain a value. But if I do something like displaying the variable in the actual class parameters, its as if it is not set... I tried moving the spot where the queries run, but still cant get it to work :(

any help is greatly appreciated!!!

Posted: Sat Aug 16, 2003 11:48 am
by PixelMaster
Try putting all those variables into the constuctor function for class FPDF:

Code: Select all

class FPDF {
    function FPDF() {
       //your variables here
       //you can now refer to them using $this->varName
    }
}
Now make sure they get initialized in the subclass too - because instantiating the subclass won't automatically call the parent class' constructor:

Code: Select all

class PDF extends FPDF {
    function PDF() {
        parent::FPDF();
    }
}
Alternatively, you could just initialize your variables in the subclass' constructor function.

Does that make a difference?