2017-08-09 122 views
0

我遇到了FPDF问题,我想创建一个While循环,它返回我的SQL查询在使用Phpmyadmin时执行的每个结果,此处的问题是它只返回一个。如果我使用
$ pdf-> Cell(190,10,''。$ pdf_info2 ['format']。'',1,1,0); 它确实打印出我想要的结果,但我需要将它们返回到表格中,如下所示。 Ps:这是我的firts问题,所以我很抱歉如果我不清楚o我的问题。 在此先感谢while FPDF中的循环仅打印1结果

$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); 
+0

'$ HTML2。='请参阅点在'='前面? –

+2

而'$ pdf_info ['format']'应该是'$ pdf_info2 ['format']''。 –

回答

0

使用此代码:

首先,你必须需要循环之前定义:$html2 = '';和while循环请参见下面的代码更新的代码$html2 .=串联:

$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); 
+0

谢谢,它的工作原理,我会在10分钟内将它标记为正确,再次感谢。 –

+0

@u_mulder检查更新的代码.. –

0

** Option1。**首先你需要合并数据与以前的数据,所以使用$html .= $html;

1选项更新$ pdf_info

$pdf_info2 

,并没有必要使用2 $pdf->WriteHTML();

所以总的代码将

$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)) { 
       $html .= '<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);