简体   繁体   中英

html php printing error

I have the following script which is an order list:

<?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
}
?>

The cell that prints the $products variable repeats each time, as a new td, but if there is more than one product I need it to print all the products in one td. Am I in a bit of a muddle?

try this:

<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
}
?>

You have the <td> tags inside your loop. Move them outside the loop, so you don't produce a new cell for each product.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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