English 中文(简体)
Table within a table, table outputted except last <td> in each row except for the first row?
原标题:

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>
最佳回答

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.

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签