循环数据表行


Looping Datatables Row

我正在做一个报告条目,它使用有输入条目的数据表。问题是最后一行显示不正确。

这是我的数据表,

$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>

错误消息是,注意:未定义的偏移量:在C:''examplep''htdocs''SOBCASHIER''html''main''divepages''srdetailstab.php中的第34行上为5

注意:正在尝试获取C:''examplep''htdocs''SOBCASHIER''html''main''divepages''srdetailstab.php中第34行上非对象的属性

注意:未定义的偏移量:在C:''examplep''htdocs''SOBCASHIER''html''main''divepages''srdetailstab.php的第37行中为5

最后一行只显示GA,没有显示代码。

请帮助我

只需从0开始for循环。类似:

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

并且在CCD_ 3中显示仅写入CCD_。

注意:无法对此进行测试,但希望它能在上运行

您忘记包含$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>