我有一个库存表需要在每一行中有一定的含量,然后在每行的最后一列中,我想循环出每个特定库存更新所使用的每个项目,即
一行将包含一个客户名列,一列用于库存交易日期,一列用于交易类型,特定技术人员以及更新中使用的某些产品的最后一列。到目前为止,我已经将前4列精确地循环出来,但最后一列仅为第一行生成。代码:
<table style="width:92%;">
<tr style="font-size:14px;">
<th style="width:150px;">Customer</th>
<th style="width:110px;">Date</th>
<th style="width:140px;">Tech</th>
<th style="width:50px;text-align:center;">Type</th>
<th>Equipment</th>
</tr>
<?php
$pd_name = array();
$compArray = array();
$prevCompany = '';
$count = 0;
$select = mysql_query("SELECT pd_name, pd_col_name, company FROM item_inventory ORDER BY company ");
while($row = mysql_fetch_array($select)){
$pd_name[$row['pd_col_name']] = $row['pd_name'];
$compArray[$row['pd_col_name']] = $row['company'];
}
$select2 = mysql_query("SELECT * FROM tech_inventory WHERE date >= '$date%' ORDER BY date DESC ");
while($row2 = mysql_fetch_array($select2)){
$count = 0;
$prevCompany = '';
?>
<tr>
<td><?php echo htmlspecialchars($row2['customerName']); ?></td>
<td><?php echo $row2['date']; ?></td>
<td><?php echo $row2['tech']; ?></td>
<td style="text-align:center;"><?php echo $row2['type']; ?></td>
<td>
<table width="200">
<?php
while (list($key, $val) = each($pd_name)){
if($row2[$key] != 0){
if($prevCompany != $compArray[$key]){
?>
<tr>
<td style="text-align:center;"><?php echo $compArray[$key]; ?></td>
</tr>
<?php
$prevCompany = $compArray[$key];
}
?>
<tr>
<td><?php echo $val ?></td>
<td><?php echo $row2[$key]; ?></td>
</tr>
<?php
$count++;
}
}
?>
</table>
</td>
</tr>
<tr><td><?php echo $count; ?></td></tr>
<?php } ?>
</table>
答案 0 :(得分:0)
这就是你要做的事情:
reset($pd_name);
while (list($key, $val) = each($pd_name))
问题在于each
逐步完成数组,一旦到达终点,就不会再继续了。因此,您必须每次都将数组指针重置为开头。