2017-08-09 10 views
0

FPDFに問題があります.Phpmyadminを使用しているときにSQLクエリが行うすべての結果を返すWhileループを作成したいのですが、 。私が使用している場合
$ pdf-> Cell(190,10、 ''。$ pdf_info2 ['format']。 ''、1,1,0); それは私が望む結果を印刷しますが、以下に示すようにテーブルに戻す必要があります。 Ps:これは私のfirtsの質問ですので、私は私の問題を明確にしていない場合は私はappolagise。事前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 = '';とループが更新されたコードのためのコードの下に表示さながらに$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

**オプション1。**まず、以前のデータとデータをマージする必要があります。$html .= $html;

オプション2更新$ 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); 
関連する問題