0
底线:如何将数组值添加到PHP
中的HTML Table
单元格?在php中添加数组值到html表
详细情况: 我有一个这样的阵列:
Array
(
[PROD-150] => Cancelled
[PROD-80245] => Pending
[PROD-BOOK-65] => Due
)
和我有一个HTML表是这样的:
<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>
下面是如何值在上表中示出:
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
echo "<td>".$val."</td>";
}
</tr>";
}
}
当我r未代码,支付状态列是这样的:
CancelledPendingDue
欲相对于产品的数量分别显示在每个单元格的阵列值。它应该是这样的:
<th>Payment Status</th>
<td>Cancelled</td>
<td>Pending</td>
<td>Due</td>
我该如何做到这一点?请帮助我。谢谢。
P.S. :: 所有的值都来自数据库。所以表格数据可以相应地变化。它可以是任何x
数字。
编辑1:
这里是我做了什么:
$table = "<tr>";
$table .= "<td>".$orderCode."</td>";
$table .= "<td>".$orderDate."</td>";
$table .= "<td>".$customerCode."</td>";
$table .= "<td>".$customerName."</td>";
$table .= "<td>".$key."</td>";
$table .= "<td align='center'>
<img src='//placehold.it/50x50>";
$table .= "</td>";
$table .= "<td>".$rows["ProdName"]."</td>";
$table .= "<td>".$productTotalAmount."</td>";
$table .= "<td>".$rows["ProdAffiCommission"]."</td>";
$table .= "<td>".$value."</td>";
$table .= "<td>".$status."</td>";
$table .= "<td>".$tab."</td>";
foreach ($bc as $value) {
$table .= "<td>".$value."</td>";
}
$table .= "</tr>";
echo $table;
输出的是这样的:
<th>Payment Status</th>
<td>Cancelled</td>
<td>Cancelled</td>
<td>Cancelled</td>
<th></th>
<td>Pending</td>
<td>Pending</td>
<td>Pending</td>
<th></th>
<td>Due</td>
<td>Due</td>
<td>Due</td>
你缺少在$数组的foreach循环回音用定界符
或这样的事情,建议。回声“”。 $ val .... – bart2puck 2015-02-07 05:32:15
已编辑..但是没有做我想要的.. – 2015-02-07 05:35:10
你如何设法让代码中没有任何TH标签的TH? – mplungjan 2015-02-07 06:32:23