显示图像取决于变量值PHP(FPDF)

时间:2018-12-28 10:27:23

标签: php mysql fpdf

我是这里的新手,很久以来一直在寻找有关此问题的答案,但我找不到解决该问题的方法。

我的项目包含一个计算器,该计算器能够保存结果,并允许用户根据需要将其导出为PDF文件。 现在,问题是,我想根据结果在PDF文件中展示图像:如果结果为M1,则显示链接到M1的图像,依此类推。 有什么办法吗?

我正在使用PHP,MYSQL数据库保存结果和输入以及fPDF。任何帮助将不胜感激。 谢谢。

    function Header(){

        global $first;
        global $second;
        global $userinput;
        global $client;
        global $project;
        global $obs;
        global $vao;
        global $perfil;
        global $valuep; //this is the final result that needs to be linked to an image
        global $lastname;
        global $firstname;
        global $lastname;
        global $email;
        global $address;
        global $country;
        global $state;
        global $phone;
        global $date;


        // Select Arial bold 15
        $this->AddFont('Raleway-Regular','','Raleway-Regular.php');
        $this->AddFont('Raleway-Bold','','Raleway-Bold.php');
        $this->SetFont('Raleway-Regular','',10);

        $this->SetFont('Raleway-Bold','',10);
        $this->Cell(22 ,5,'Name: ' . $firstname, '' .$lastname,0,0);
        $this->Cell(20 ,5,'Email: ' . $email,0,1);
        $this->Cell(20 ,5,'Phone: ' . $phone,0,1);
        $this->Cell(20 ,5,'Website: ' . $state,0,1);



        $this->Image('headerimage.jpg',160,15,30);

        $this->Cell(100,0,'',0,0);
        $this->Ln(5);

        $this->SetFont('Raleway-Regular','',10);
        $this->SetFillColor(0,0,0);
        $this->SetDrawColor(255,255,255);


        $this->Cell(25 ,5,"Project Name: " . $project ,0,1);
        $this->Cell(24.5,5,'Client: ' .$client,1,0);
        $this->Cell(25,5,'Date: ' . $date,0,1);

        //

        $this->Cell(0 ,5,'',0,1);


        //

        $this->Cell(190,0.3,'','T',0,'',true);

        $this->Cell(0 ,5,'',0,1);


         $this->SetFont('Raleway-Bold','',12);

        $this->Cell(85 ,5,'Inputs ',0,0);
        $this->Cell(25 ,5,'Span Details ',0,1);

        $this->Cell(0 ,5,'',0,1);
        $this->SetFont('Raleway-Regular','',11);
        $this->Cell(190,0.3,'','T',0,'',true);
        $this->Cell(0 ,5,'',0,1);
        $this->Cell(25 ,5,'Name of Span: ' . $vao,0,0);

        $this->Cell(0 ,5,'',0,1);
        $this->Cell(0 ,5,'',0,1);
        $this->Cell(85 ,5,'Wind Action: ' .$perfil . '' . $userinput . ' kN/m2]',0,0);

         $this->SetFont('Raleway-Regular','',11);
         $this->Cell(30 ,5,'Height: ' . $first . ' m',0,0);
         $this->Cell(30 ,5,'Width: ' . $second . ' m',0,1);

        //
         $this->Cell(0 ,5,'',0,1);
        //
         $this->Cell(190,0.3,'','T',0,'',true);
         $this->Cell(0 ,5,'',0,1);
         $this->SetFont('Raleway-Regular','',11);
         $this->SetFont('Raleway-Bold','',12);
         $this->Cell(25 ,5,'Solution ',0,1);
         $this->SetFont('Raleway-Regular','',11);
         $this->Cell(0 ,5,'',0,1);
         $this->Cell(190,0.3,'','T',0,'',true);
         $this->Cell(0 ,5,'',0,1);

         $this->Cell(25 ,5,'Final result: ' . $valuep,0,1); //image here next to the text
        //
        $this->Cell(0 ,5,'',0,1);
        //

          $this->Cell(0 ,5,'',0,1);
          $this->Cell(0 ,5,'',0,1);
          $this->Cell(0 ,5,'',0,1);

          $this->SetFont('Raleway-Bold','',12);
          $this->Cell(25 ,5,'Observations: ',0,1);
          $this->SetFillColor(255,255,255);

    }



    function Footer(){


   // Go to 1.5 cm from bottom
    $this->SetY(-15);
    // Select Arial italic 8
    $this->SetFont('Raleway-Bold','',5);
    // Print centered page number
    $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
    $this->Cell(25,5,"Vestibulum placerat lorem venenatis nulla tempor maximus a ut elit.",0,0,'R');
    } }


$pdf = new PDF('P','mm','A4'); $pdf->AliasNbPages('{pages}');

$pdf->SetAutoPageBreak(true,5); $pdf->AddPage();


$pdf->SetFont('Raleway-Regular','',10); $text=str_repeat('' .$obs,1); $pdf->Write(5,$text); $pdf->SetDrawColor(255,255,255);



$pdf->Output();

1 个答案:

答案 0 :(得分:0)

这取决于您可能获得多少结果以及图片是否不同。

由于您使用的是mySQL,建议您创建一个包含所有结果和图像的表。

然后读出结果,瞧瞧,您已经在图像上附加了图像。