表中表,输出除最后一个之外的表除了第一行之外的每一行?
我有一个库存表,需要在每一行中都有一定的内容,然后在每行的最后一列中,我想循环出每个特定库存更新使用的每个项目,即
一行将有一列用于客户名称,一列表示库存交易日期,一列表示交易类型,具体技术人员,最后一列表示更新中使用的某些产品。到目前为止,我所得到的内容可以很好地循环出前 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>
I've got an inventory table that needs to have certain in each row, and then in the last column in each row, i want to loop out each item that was used per a specific inventory update i.e.
one row would have one column for the customername, one column for the date of the inventory transaction, one for the type of transaction, the specific technician and the last column for the certain products that were used in the update. what i've got so far loops out the first 4 columns fine, but the last column only gets generated for the first row. code:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是你必须做的:
问题是
each
遍历数组,一旦到达末尾,它就不会再继续了。因此,每次都必须将数组指针重置到开头。This is what you have to do:
The problem was that
each
steps through the array and once it reaches the end, it won't go any further. Therefore, you have to reset the array pointer to the beginning every time.