<small id='nMAxR'></small><noframes id='nMAxR'>

<legend id='nMAxR'><style id='nMAxR'><dir id='nMAxR'><q id='nMAxR'></q></dir></style></legend>
        <bdo id='nMAxR'></bdo><ul id='nMAxR'></ul>
    1. <i id='nMAxR'><tr id='nMAxR'><dt id='nMAxR'><q id='nMAxR'><span id='nMAxR'><b id='nMAxR'><form id='nMAxR'><ins id='nMAxR'></ins><ul id='nMAxR'></ul><sub id='nMAxR'></sub></form><legend id='nMAxR'></legend><bdo id='nMAxR'><pre id='nMAxR'><center id='nMAxR'></center></pre></bdo></b><th id='nMAxR'></th></span></q></dt></tr></i><div id='nMAxR'><tfoot id='nMAxR'></tfoot><dl id='nMAxR'><fieldset id='nMAxR'></fieldset></dl></div>
      <tfoot id='nMAxR'></tfoot>

        PHP While 循环只显示最后一行

        时间:2023-09-20
      1. <tfoot id='hNARB'></tfoot>

        <small id='hNARB'></small><noframes id='hNARB'>

            <legend id='hNARB'><style id='hNARB'><dir id='hNARB'><q id='hNARB'></q></dir></style></legend>

                <tbody id='hNARB'></tbody>

                  <bdo id='hNARB'></bdo><ul id='hNARB'></ul>
                  <i id='hNARB'><tr id='hNARB'><dt id='hNARB'><q id='hNARB'><span id='hNARB'><b id='hNARB'><form id='hNARB'><ins id='hNARB'></ins><ul id='hNARB'></ul><sub id='hNARB'></sub></form><legend id='hNARB'></legend><bdo id='hNARB'><pre id='hNARB'><center id='hNARB'></center></pre></bdo></b><th id='hNARB'></th></span></q></dt></tr></i><div id='hNARB'><tfoot id='hNARB'></tfoot><dl id='hNARB'><fieldset id='hNARB'></fieldset></dl></div>
                  本文介绍了PHP While 循环只显示最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 TCPD 库来生成表格的 PDF.

                  I'm using TCPDF library to generate PDF of a table .

                  表的行数很少,比如 10

                  Table has few number of rows say 10

                  其中两行发票编号相同78650"

                  现在我按发票编号选择,并根据需要生成带有两行的 PDF.

                  Now i am selecting by invoice number and as desired it should generate PDF with two rows.

                  但它只获取最后一行的第二行.那是 Serial no 2 只被拿走了.

                  But instead it is only fetching the second row that is the last row. That is Serial no 2 is only taken .

                  代码如下:

                  <?php
                  require_once('TCPDF/tcpdf.php');
                  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
                  $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
                  $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                  
                  if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
                  require_once(dirname(__FILE__).'/lang/eng.php');
                  $pdf->setLanguageArray($l);
                  }
                  $pdf->SetFont('helvetica', '', 9);
                  $pdf->AddPage();
                  
                  $html1 = '<table  cellspacing="0" class="table table-striped">
                  <tr>
                  
                  <th>SL No.</th>
                  
                  <th>Product</th>
                  <th>Description</th>
                  <th>Qty</th>
                  <th>Total</th>
                  </tr>';
                  
                  $sql = ("select * from invoice WHERE invoice_no = 78650 ORDER BY invoice_id ASC");
                  $result=mysqli_query($connection,$sql);
                  $i = 1;
                  while($row = mysqli_fetch_array($result)){
                  $pr = $row['product'];  
                  $dr = $row['description'];  
                  $qty = $row['qty']; 
                  $total = $row['total']; 
                  
                  $html2 =  "<tr>
                  
                  <td>".$i."</td>                         
                  <td>".$pr."</td>
                  <td>".$dr."</td>
                  <td>".$qty."</td>
                  <td>".$total."</td>
                  </tr>";
                  
                  $i++; } 
                  
                  $sql_1 = ("select *,SUM(total)as tot from invoice WHERE invoice_no = 78650 GROUP BY invoice_no");
                  $result_1=mysqli_query($connection,$sql_1);
                  $row_1 = mysqli_fetch_array($result_1);
                  $tot = $row_1['tot']; 
                  $html3 =    "<tr>
                  <td></td>
                  
                  <td></td>
                  <td></td>
                  <td>Total: </td>
                  <td>".$tot."</td>
                  </tr>                       
                  </table>";
                  $html = $html1.$html2.$html3;
                  $pdf->writeHTML($html, true, 0, true, 0);
                  $pdf->lastPage();
                  $pdf->Output('htmlout.pdf', 'I');
                  ?>
                  

                  推荐答案

                  那是因为对于迭代,您正在替换 $html2 的内容.您需要改为附加内容.

                  That's because for iteration you're replacing the content of $html2. You will need to append the content instead.

                  因此,将空白的 $html2 变量移出循环并在迭代循环时附加结果.

                  So take the blank $html2 variable outside the loop and append the result as you iterate the loop.

                  代码看起来像这样,

                  $html2="";
                  while($row = mysqli_fetch_array($result)){
                  $pr = $row['product'];  
                  $dr = $row['description'];  
                  $qty = $row['qty']; 
                  $total = $row['total']; 
                  
                  $html2 = $html2."<tr>
                  <td>".$i."</td>                         
                  <td>".$pr."</td>
                  <td>".$dr."</td>
                  <td>".$qty."</td>
                  <td>".$total."</td>
                  </tr>";
                  
                  $i++; 
                  
                  } 
                  

                  这篇关于PHP While 循环只显示最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Jquery 循环无法正常工作? 下一篇:从while循环中获取计数器的更简单方法?

                  相关文章

                  最新文章

                  <legend id='JxgcM'><style id='JxgcM'><dir id='JxgcM'><q id='JxgcM'></q></dir></style></legend><tfoot id='JxgcM'></tfoot>

                      <bdo id='JxgcM'></bdo><ul id='JxgcM'></ul>

                      <small id='JxgcM'></small><noframes id='JxgcM'>

                    1. <i id='JxgcM'><tr id='JxgcM'><dt id='JxgcM'><q id='JxgcM'><span id='JxgcM'><b id='JxgcM'><form id='JxgcM'><ins id='JxgcM'></ins><ul id='JxgcM'></ul><sub id='JxgcM'></sub></form><legend id='JxgcM'></legend><bdo id='JxgcM'><pre id='JxgcM'><center id='JxgcM'></center></pre></bdo></b><th id='JxgcM'></th></span></q></dt></tr></i><div id='JxgcM'><tfoot id='JxgcM'></tfoot><dl id='JxgcM'><fieldset id='JxgcM'></fieldset></dl></div>