duanping1632 2018-05-19 10:16
浏览 50

未定义的变量:FPDF中的pdf

 $query = mysqli_query($con,"select * from s_users
        where
        s_id = '".$_GET['s_id']."'");   
    $row = mysqli_fetch_array($query);
    if ($row['status'] == 1) { //1 
    $pdf = new PDF_Code128('P','mm','A4');
    $pdf->AddPage();
    $pdf->Cell(190  ,220,'',1,0);
     $pdf->image('images/logo.png', 14, 16, -200);
    $pdf->image($row['imgdata'], 163, 16, -210);
    $pdf->SetFont('Arial','B',14);
    } else {
    $pdf->image('images/profiledefault.jpg', 163, 16, -210);
    }

this is my code for displaying profile picture using FPDF,i want to have a default picture display when there is no profile picture. am using an IFELSE statement, but i get undefined variable pdf in the else statement

  • 写回答

1条回答 默认 最新

  • douluan1533 2018-05-19 10:19
    关注

    Your issue is with the if statement. If status=1 then you're defining $pdf. If this isn't the case then you don't.

    You should re-jig your code along these lines ...

    $query = mysqli_query($con,"select * from s_users where s_id = '".$_GET['s_id']."'");   
    $row = mysqli_fetch_array($query);
    
    $pdf = new PDF_Code128('P','mm','A4');
    $pdf->AddPage();
    $pdf->Cell(190  ,220,'',1,0);
    
    if ($row['status'] == 1) { //1 
        $pdf->image('images/logo.png', 14, 16, -200);
        $pdf->image($row['imgdata'], 163, 16, -210);
    } else {
        $pdf->image('images/profiledefault.jpg', 163, 16, -210);
    }
    
    $pdf->SetFont('Arial','B',14);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器