duanduanxi9441 2017-08-09 15:51
浏览 28
已采纳

而FPDF中的循环只打印1个结果

i'm having a problem with FPDF, i want to create a While Loop that returns every result that my SQL query does when i use Phpmyadmin, the problem here is that it only returns one. If i use
$pdf->Cell(190,10,''.$pdf_info2['format'].'',1,1,0); it does print the result i want, but i need to return them in the table as i show below. Ps: This is my firts question so i appolagise if i wasn't that clear o my problem. Thanks in advance

$html='<table border="0">
            <tr>
                <td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
                <td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
                <td width="150" height="40" bgcolor="#e6e6e6">&nbsp;</td>
                <td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
                <td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
            </tr>';
            while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
                $html2 = '<tr>
<td width="150" height="40"   bgcolor="#e6e6e6">'.$pdf_info['format'].'</td>
                <td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
                <td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
                <td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
                <td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
            </tr>';
            }

$pdf->WriteHTML($html);
$pdf->WriteHTML($html2);
  • 写回答

2条回答 默认 最新

  • duanmaduan1848 2017-08-09 15:53
    关注

    Use this code:

    First you must need to define before loop: $html2 = ''; and concatenate with $html2 .= in while loop see below code for updated code:

    $html2 ='';
    $html ='<table border="0">
    <tr>
        <td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
        <td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
        <td width="150" height="40" bgcolor="#e6e6e6">&nbsp;</td>
        <td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
        <td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
    </tr>';
    
    while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
        $html2 .='<tr>
            <td width="150" height="40"   bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
            <td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
            <td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
            <td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
            <td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
        </tr>';
    }
    
    $pdf->WriteHTML($html);
    $pdf->WriteHTML($html2);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 quartus II 9.0闪退问题怎么解决啊,急
  • ¥20 求自动化运维语料数据集
  • ¥30 广告检测流量作弊案例 IDEA运行代码报错 连接不上metastore 检测了环境配置没有问题 请求远程解决加VX问细节问题 不加的不回复
  • ¥15 matlab图像融合代码被嫌弃太简单,求改进。第一步改成直接读取三张图片,不读取文件夹
  • ¥20 微处理器原理与应用(私有偿)
  • ¥50 8051单片机关于ADC0809的应用
  • ¥15 有没有能拿来练练手写完发给我
  • ¥15 禁止修改windows系统时间
  • ¥50 kinect连接win11笔电导致音视频设备消失
  • ¥15 python线性查找题