将行显示为列

时间:2016-09-10 12:01:02

标签: php html

以下代码在一行中显示产品名称,在新行中显示数量,价格和小计,如何在同一行中显示所有这些。输出截图如下所示。

code output

            <table class="table table-striped table-condensed">
            <tbody>
            <?php
            $r = 1;
            $tax_summary = array();
            foreach ($rows as $row) {
                if (isset($tax_summary[$row->tax_code])) {
                    $tax_summary[$row->tax_code]['items'] += $row->quantity;
                    $tax_summary[$row->tax_code]['tax'] += $row->item_tax;
                    $tax_summary[$row->tax_code]['amt'] += ($row->quantity * $row->net_unit_price) - $row->item_discount;
                } else {
                    $tax_summary[$row->tax_code]['items'] = $row->quantity;
                    $tax_summary[$row->tax_code]['tax'] = $row->item_tax;
                    $tax_summary[$row->tax_code]['amt'] = ($row->quantity * $row->net_unit_price) - $row->item_discount;
                    $tax_summary[$row->tax_code]['name'] = $row->tax_name;
                    $tax_summary[$row->tax_code]['code'] = $row->tax_code;
                    $tax_summary[$row->tax_code]['rate'] = $row->tax_rate;
                }
                echo '<tr><td colspan="2">#' . $r . ': &nbsp;&nbsp;' . product_name($row->product_name) . ($row->variant ? ' (' . $row->variant . ')' : '') . '<span class="pull-right">' . $row->tax_code . '</span></td></tr>';
                echo '<tr><td>' . $this->sma->formatNumber($row->quantity) . ' x ';

                if ($row->item_discount != 0) {
                    echo '<del>' . $this->sma->formatMoney($row->net_unit_price + ($row->item_discount / $row->quantity) + ($row->item_tax / $row->quantity)) . '</del> ';
                }

                echo $this->sma->formatMoney($row->net_unit_price + ($row->item_tax / $row->quantity)) . '</td><td class="text-right">' . $this->sma->formatMoney($row->subtotal) . '</td></tr>';
                $r++;
            }
            ?>
            </tbody>
            <tfoot>
            <tr>

1 个答案:

答案 0 :(得分:0)

尝试下面的内容,但可能会破坏格式:

<table class="table table-striped table-condensed">
<tbody>
<?php
$r = 1;
$tax_summary = array();
foreach ($rows as $row) {
    if (isset($tax_summary[$row->tax_code])) {
        $tax_summary[$row->tax_code]['items'] += $row->quantity;
        $tax_summary[$row->tax_code]['tax'] += $row->item_tax;
        $tax_summary[$row->tax_code]['amt'] += ($row->quantity * $row->net_unit_price) - $row->item_discount;
    } else {
        $tax_summary[$row->tax_code]['items'] = $row->quantity;
        $tax_summary[$row->tax_code]['tax'] = $row->item_tax;
        $tax_summary[$row->tax_code]['amt'] = ($row->quantity * $row->net_unit_price) - $row->item_discount;
        $tax_summary[$row->tax_code]['name'] = $row->tax_name;
        $tax_summary[$row->tax_code]['code'] = $row->tax_code;
        $tax_summary[$row->tax_code]['rate'] = $row->tax_rate;
    }
    echo '<tr><td colspan="2">#' . $r . ': &nbsp;&nbsp;' . product_name($row->product_name) . ($row->variant ? ' (' . $row->variant . ')' : '') . '<span class="pull-right">' . $row->tax_code . '</span>';
    echo '' . $this->sma->formatNumber($row->quantity) . ' x ';

    if ($row->item_discount != 0) {
        echo '<del>' . $this->sma->formatMoney($row->net_unit_price + ($row->item_discount / $row->quantity) + ($row->item_tax / $row->quantity)) . '</del> ';
    }

    echo $this->sma->formatMoney($row->net_unit_price + ($row->item_tax / $row->quantity)) . '' . $this->sma->formatMoney($row->subtotal) . '</td></tr>';
    $r++;
}
?>
</tbody>