【问题标题】:create invoice from a shopping cart从购物车创建发票
【发布时间】:2016-01-08 11:12:51
【问题描述】:

我正在尝试将购物车的输出显示到发票中。数据显示但不正确。

下面是我的代码

l

 <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>Qty</th>
                                        <th>Item</th>
                                        <th>Subtotal</th>
                                    </tr>                                    
                                </thead>
                                
                                     <?php
			if(is_array($_SESSION['cart'])){
            	
				$max=count($_SESSION['cart']);
				for($i=0;$i<$max;$i++){
					$pid=$_SESSION['cart'][$i]['productid'];
					$q=$_SESSION['cart'][$i]['qty'];
					$pname=get_product_name($pid);
					if($q==0) continue;
			?>        
                                <tbody>
                                         
       // Display
                                    <tr>
                                        <td><?php echo $q?></td>
                                        <td><?php echo $pname?></td>
                                        <td>$ <?php echo get_price($pid)*$q?></td>
                                    </tr>
                                </tbody>
                            </table>                            
                        </div><!-- /.col -->
                    </div><!-- /.row -->

  <?php					
				}
			?>
                    <div class="row">
                        <!-- accepted payments column --><!-- /.col -->
                        
                        <div class="col-xs-6" align="right">
                            <p class="lead">&nbsp;</p>
                            <div class="table-responsive">
                                <table class="table">
                                    <tr>
                                        <th>Total:</th>
                                        <td> $<?php echo get_order_total()?></td>
                                    </tr>
                                    
                                    	<?php
            }
			else{
				echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
			}
		?>
                                </table>
                            </div>
                      </div><!-- /.col -->
                     

我想安排它,以便它可以像第一个结果一样显示。

希望这次能发送。

【问题讨论】:

  • 有什么错误?什么是预期的不起作用的行为?
  • 正如您在我添加的图片中看到的那样,其他产品没有正确对齐
  • 我在图片中没有看到。一个快速提示,首先将标记与业务逻辑分开。这是一个糟糕的设计,你会遇到很多意想不到的问题。
  • @anelka 请检查我的答案。

标签: php html mysql


【解决方案1】:

始终编写缩进代码。它将帮助您调试并且看起来不错。

我尝试按照图像中的要求更新 html。请尝试如下:

<table class="table table-striped">
    <thead>
        <tr>
            <th>Qty</th>
            <th>Item</th>
            <th>Subtotal</th>
        </tr>
    </thead>
    <tbody>
    <?php
    if(is_array($_SESSION['cart']))
    {
        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++)
        {
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=$_SESSION['cart'][$i]['qty'];
            $pname=get_product_name($pid);
            if($q==0) continue;
            ?>
            <tr>
                <td><?php echo $q?></td>
                <td><?php echo $pname?></td>
                <td>$ <?php echo get_price($pid)*$q?></td>
            </tr>
        <?php                   
        } 
    }
    else
    { ?>
        <tr bgColor='#FFFFFF'>
            <td>There are no items in your shopping cart!</td>
        </tr>
    <?php } ?>
    </tbody>
</table>
<?php
if(is_array($_SESSION['cart']))
{ ?>
<div class="row">
    <div class="col-xs-6" align="right">
        <p class="lead">&nbsp;</p>
        <div class="table-responsive">
            <table class="table">
                <tr>
                    <th>Total:</th>
                    <td>$<?php echo get_order_total()?>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<?php } ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    相关资源
    最近更新 更多