[英]i want to display data which is coming from loop in a table form
My PHP Code is Given Below. 我的PHP代码在下面给出。
<?php
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$sid=$_SESSION['cart'][$i]['STOREID'];
$q=$_SESSION['cart'][$i]['qty'];
$Product=get_product_name($pid,$sid);
$price=get_price($pid,$sid);
echo $Product;
?>
<table border='1'>
<tr>
<th>Ordered Product</th
<th>Price</th>
<th>Quantity</th>
</tr>
</table>
I want to display the product in table under Ordered Product. 我想在订购产品下的表中显示产品。
It depends on which format you're willing to display. 这取决于您愿意显示的格式。 Let me show an example:
让我举一个例子:
<table border='1'> <thead> <tr> <th>Ordered Product</th> <th>Price</th> <th>Quantity</th> </tr> </thead> <tbody> <?php for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $sid=$_SESSION['cart'][$i]['STOREID']; $q=$_SESSION['cart'][$i]['qty']; $Product=get_product_name($pid,$sid); $price=get_price($pid,$sid); ?> <tr> <th><?php echo $product ?></th> <th><?php echo $price ?></th> <th><?php echo $q ?></th> </tr> <?php } ?> </tbody> </table>
One suggestion that I'd like to provide is to avoid writing HTML codes within echo. 我想提供的一项建议是避免在echo中编写HTML代码。 It's the best if you keep the PHP and HTML codes separeted.
最好将PHP和HTML代码分隔开。
Hope this helps! 希望这可以帮助!
Peace! 和平! xD
xD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.