循环数据表行

时间:2016-04-04 12:41:45

标签: javascript php jquery mysql mysqli

我正在使用具有输入条目的数据表的reportentry。问题是最后一行没有正确显示。

这是我的数据表,

$flightsCount = $_POST['flights'];
<tbody>
                    <?php
                        for($i = 1; $i <= count($flightsCount);$i++){
                            $flightRoute = $mysqli->query("SELECT flight_region FROM mst_flight WHERE flight_id = '$flightsCount[$i]'")->fetch_object()->flight_region;
                            echo "<tr>";
                                echo "<td>$i</td>";
                                echo "<td>GA $flightsCount[$i]</td>";
                                echo "<td>$flightRoute</td>";
                                echo "<td>$newDate</td>";
                                echo "<td><input type='text'/></td>";
                                echo "<td><input type='text'/></td>";
                                echo "<td><input type='text'/></td>";
                            echo "</tr>";
                        }
                    ?>
                </tbody>

错误信息是, 注意:未定义的偏移量:第34行的C:\ xampp \ htdocs \ SOBCASHIER \ html \ main \ divpages \ srdetailstab.php中的5

注意:尝试在第34行的C:\ xampp \ htdocs \ SOBCASHIER \ html \ main \ divpages \ srdetailstab.php中获取非对象的属性

注意:未定义的偏移量:第37行的C:\ xampp \ htdocs \ SOBCASHIER \ html \ main \ divpages \ srdetailstab.php

最后一行仅显示GA而未显示代码。

请帮帮我

2 个答案:

答案 0 :(得分:1)

for开始0循环。像:

for($i = 0; $i < count($flightsCount);$i++)

并显示在td中,只需撰写$i + 1

注意:无法测试,但希望它能够正常运行

答案 1 :(得分:0)

您忘记为$ flightsCount

添加0索引

您的代码应更新为:

$flightsCount = $_POST['flights'];
<tbody>
                    <?php
                        for($i = 0; $i < count($flightsCount);$i++){
                            $flightRoute = $mysqli->query("SELECT flight_region FROM mst_flight WHERE flight_id = '$flightsCount[$i]'")->fetch_object()->flight_region;
                            echo "<tr>";
                                echo "<td>".($i+1)."</td>";//updated to include the index update
                                echo "<td>GA $flightsCount[$i]</td>";
                                echo "<td>$flightRoute</td>";
                                echo "<td>$newDate</td>";
                                echo "<td><input type='text'/></td>";
                                echo "<td><input type='text'/></td>";
                                echo "<td><input type='text'/></td>";
                            echo "</tr>";
                        }
                    ?>
                </tbody>