打印发票数据空白php foreach循环错误

时间:2019-07-06 11:11:18

标签: php

我要打印发票数据。但是有些错误只能打印一张图像。如何在发票中打印所有数据我正在使用PHP 7.2并循环foreach请帮助我...

error->Warning: Invalid argument supplied for foreach() in D:\xammp\htdocs\tam\admin\invoice.php on line 133

PHP GET id智能发票数据脚本

 <?php 
require 'setting/config.php';
$id=$_GET['id'];
$query="select * from orders where id='$id'";
$galrun=mysqli_query($conn, $query);
$result=mysqli_fetch_assoc($galrun);
$total=$result['total']; 

 $array[0]=$result['image'];
 $array[1]=$result['productName'];
 $array[2]=$result['product_qty'];
 $array[3]=$result['salseprice'];

$resultdata= implode(",", $array);

 ?>

HTML发票

 <table class="table">
              <thead>
                   <tr>
                     <th>Sr. No.</th>
                    <th>image</th>
                     <th>Description</th>
                     <th>Qty</th>
                     <th>Amount</th>
                      <th>Total</th>
                    </tr>
             </thead>
             <tbody>
        <?php

                      foreach ($resultdata as $item){
                        ?>
                      <tr>
                       <td> ? </td>
                       <td><img src="image/product/<?php echo $item[0] ; ?>" style="width:100px;height:50px;"></td>
                       <td><?php echo $item[1] ; ?></td>
                       <td><?php echo $item[2] ; ?></td>
                       <td><?php echo $item[3] ; ?></td>
                       <td><?php echo $total ; ?</td>

                     </tr>
                      <?php }?>                               
           </tbody>
       </table>

1 个答案:

答案 0 :(得分:0)

您尝试遍历$resultdata,但是由于这部分,它是一个字符串:

$resultdata= implode(",", $array);

PHP implode()返回一个字符串。

相关问题