【问题标题】:html php printing errorhtml php打印错误
【发布时间】:2012-07-11 02:00:19
【问题描述】:

我有以下脚本,它是一个订单列表:

<?php
$manifest_query = tep_db_query("SELECT o.franchise_id, o.orders_id, 
    o.customers_id, o.delivery_name, o.delivery_street_address [...]");
while ($manifest = tep_db_fetch_array($manifest_query)){
?>
<tr>
<td height="50" align="center"><?php echo $manifest['orders_id'] ;?></td>
<td cellpadding="2"><?php echo $manifest['delivery_name'] .'<br> '. 
    $manifest['delivery_street_address'] .'<br> '. 
    $manifest['delivery_city'].'<br> '. 
    $manifest['delivery_postcode'].'<br> '. 
    $manifest['delivery_state'].'<br> '. $manifest['customers_telephone'] ;?>
</td>

<?php
$products_query = tep_db_query("select products_model, products_name, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$manifest['orders_id'] . "'");
while ($products = tep_db_fetch_array($products_query)) {
?>

<td><?php echo$products['products_quantity'] . '&nbsp;x&nbsp;' . $products['products_name'] . 
    '<br> ' . '&nbsp;&nbsp;'.$products['products_model'] .'<br>';?></td>
<?php
}
?>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2"></td>
</tr>

<?php
}
?>

打印$products 变量的单元格每次都会重复,作为一个新的 td,但如果有多个产品,我需要它来打印一个 td 中的所有产品。我是不是有点糊涂了?

【问题讨论】:

  • 在 while 循环中打印了 &lt;td&gt; 标签。如果你把它们放在外面,它们应该只做一个&lt;td&gt;

标签: php html loops html-table


【解决方案1】:

您的循环中有&lt;td&gt; 标签。将它们移到循环之外,这样您就不会为每个产品生成一个新单元格。

【讨论】:

    【解决方案2】:

    试试这个:

    <tr>
    <td height="50" align="center"><?php echo $manifest['orders_id'] ;?></td>
    <td cellpadding="2"><?php echo $manifest['delivery_name'] .'<br> '. $manifest['delivery_street_address'] .'<br> '. $manifest['delivery_city'].'<br> '. $manifest['delivery_postcode'].'<br> '. $manifest['delivery_state'].'<br> '. $manifest['customers_telephone'] ;?></td>
    <td>
    <?php
    $products_query = tep_db_query("select orders_products_id, orders_id, products_id, products_model, products_name, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$manifest['orders_id'] . "'");
    
    while ($products = tep_db_fetch_array($products_query)) {
    ?>
    
    <?php echo$products['products_quantity'] . '&nbsp;x&nbsp;' . $products['products_name'] . '<br> ' . '&nbsp;&nbsp;'.$products['products_model'] .'<br>';?>
    <?php
    }
    ?>
    </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    
    <td>&nbsp;</td>
    
    <td colspan="2"></td>
    
    </tr>
    
    <?php
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多