将数组值添加到php中的html表 [英] Add array value to html table in php
问题描述
底线:如何将数组值附加到PHP中的HTML表格单元格?
详细情况:我有一个这样的数组:
数组
(
[PROD-150] => ;取消
[PROD-80245] =>待定
[PROD-BOOK-65] =>到期
)
我有一个这样的HTML表:
< < span class =code-leadattribute> tr >
< th > 订单代码< < span class =code-leadattribute> / th >
< th > 订单日期< / th >
< > 客户代码< / th >
< > 客户名称< / th >
< th > 产品代码< / th >
< th > 产品图片< / th >
< th > 产品名称< / th >
< ; th > 产品金额< / th >
< th > 佣金百分比< ; / th >
< th > Com任务金额< / th >
< th > 订单状态< / th >
< th > 付款状态< / th >
< / tr >
以下是上表中数值的显示方式:
foreach ($ affiCodeAndAmount as $ key => $ value){
$ query = SELECT * FROM products WHERE ProdCode ='。$ key。 ';
$ validate->查询($ query);
while ($ rows = $ validate-> FetchAllDatas()){
foreach ($ prdOrdQty as $ i){
$ productTotalAmount = $ i * $ rows [ ProdRate];
}
echo
< tr>
< td>。$ orderCode。 < ; / td>
< td>。$ orderDate。 < / td> ;
< td>。$ customerCode。 < / td>
< td>。$ customerName。 < / td>
< ; td>。$ key。 < / td>
< td align ='center'>
< img src ='// placehold.it/50x50'>
< / td>
< td>。$ rows [ ProdName]。< span class =code-string> < / td>
< td>。$ productTotalAmount。 < / td>
< td>。$ rows [ ProdAffiCommission]。 < / td>
< td>。$ value。 < / td>
< td>。$ status。 < / td>;
foreach($ array as $ val){ // $ array是上面的数组
< td> 。$ val。 < / td>;
}
< / tr > ;
}
}
当我运行代码时,付款状态栏就像这样:
CancelledPendingDue
我想分别显示每个单元格中的数组值产品。它应该是这样的:
< th > 付款状态< / th >
< td > 已取消< / td >
< td > 待定< / td >
< td > 到期< / td >
我如何实现这一目标?请帮助我。谢谢。
P.S。 ::所有值都来自数据库。所以表数据可以相应变化。它可以是任何x数。
affiCodeAndAmount as < span class =code-sdkkeyword>
key =>
value){
Bottom Line: How to append array values to the HTML Table cell in PHP ?
Detailed Situation: I have an array like this:
Array
(
[PROD-150] => Cancelled
[PROD-80245] => Pending
[PROD-BOOK-65] => Due
)
And I have a HTML table like this:
<tr>
<th>Order Code</th>
<th>Order Date</th>
<th>Customer Code</th>
<th>Customer Name</th>
<th>Products Code</th>
<th>Products Image</th>
<th>Products Name</th>
<th>Product Amount</th>
<th>Commission Percentage</th>
<th>Commission Amount</th>
<th>Order Status</th>
<th>Payment Status</th>
</tr>
Here's the how values are shown in the above table:
foreach ($affiCodeAndAmount as $key => $value) {
$query = "SELECT * FROM products WHERE ProdCode = '".$key."'";
$validate->Query($query);
while ($rows = $validate->FetchAllDatas()) {
foreach ($prdOrdQty as $i) {
$productTotalAmount = $i * $rows["ProdRate"];
}
echo "
<tr>
<td>".$orderCode."</td>
<td>".$orderDate."</td>
<td>".$customerCode."</td>
<td>".$customerName."</td>
<td>".$key."</td>
<td align='center'>
<img src='//placehold.it/50x50'>
</td>
<td>".$rows["ProdName"]."</td>
<td>".$productTotalAmount."</td>
<td>".$rows["ProdAffiCommission"]."</td>
<td>".$value."</td>
<td>".$status."</td>";
foreach($array as $val) { // $array is the above array
"<td>".$val."</td>";
}
</tr>";
}
}
When I run the code, the Payment Status Column is like this:
CancelledPendingDue
I want to display the array values in each cell separately with respect to the number of products. It should be like this:
<th>Payment Status</th>
<td>Cancelled</td>
<td>Pending</td>
<td>Due</td>
How do I achieve that ? Kindly help me out. Thanks.
P.S.:: All the values are coming from the database. So the table data can vary accordingly.. It can be any x number.
affiCodeAndAmount as
key =>
value) {
这篇关于将数组值添加到php中的html表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!