繁体   English   中英

html php循环错误

[英]html php looping error

我有以下脚本是订单列表:

<?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,但是如果有1个以上的产品,则需要用它在一个td中打印所有产品。 我有点糊涂了吗?

<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)) {
?>

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

只是放在while循环外。 像上面一样

就像将包含<td></td>移到while()循环外一样简单:

<?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>
<td><!-- open here -->
<?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)) {
?>
<?php echo$products['products_quantity'] . '&nbsp;x&nbsp;' . $products['products_name'] . 
    '<br> ' . '&nbsp;&nbsp;'.$products['products_model'] .'<br>';?>
<?php
}
?>
</td><!-- and close here -->
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2"></td>
</tr>

<?php
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM