根据变量值php(fpdf)显示图像

k2fxgqgv  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(313)

我是新来的,我一直在寻找一个关于这个问题的答案有一段时间了,但我想不出一个办法来解决这个问题。
我的项目由一个计算器组成,它可以保存一个结果,如果用户愿意的话,可以将其导出为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();
42fyovps

42fyovps1#

这取决于你可能得到多少结果,图片是否不同。
因为您使用的是mysql,所以我建议创建一个包含所有结果和图像的表。
然后读出结果,瞧,你有图像附在上面了。

相关问题