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条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算