表中表,输出除最后一个之外的表除了第一行之外的每一行?

发布于 2024-08-10 18:40:58 字数 3192 浏览 5 评论 0原文

我有一个库存表,需要在每一行中都有一定的内容,然后在每行的最后一列中,我想循环出每个特定库存更新使用的每个项目,即

一行将有一列用于客户名称,一列表示库存交易日期,一列表示交易类型,具体技术人员,最后一列表示更新中使用的某些产品。到目前为止,我所得到的内容可以很好地循环出前 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海拔太高太耀眼 2024-08-17 18:40:58

这就是你必须做的:

reset($pd_name);
while (list($key, $val) = each($pd_name))

问题是 each 遍历数组,一旦到达末尾,它就不会再继续了。因此,每次都必须将数组指针重置到开头。

This is what you have to do:

reset($pd_name);
while (list($key, $val) = each($pd_name))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文