繁体   English   中英

未显示第一行html

[英]The first html row is not being displayed

因此,假设我的数据库中有10行。 但是,在mysql查询后,html表中仅显示9行。 我需要数据库中的每一行都显示在html表中。

我希望有人能指出我正确的方向。 如果需要提供更多详细信息,我会在这里。

这是我的代码:

<?php
$sqlQuery = "SELECT * FROM periods";
$result = mysqli_query($conn, $sqlQuery);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $id = $row['id'];
        $out = $row['fell_out'];
        $in = $row['fell_in'];
        $sum = $row['sum'];
        $nextEstimate = $row['next_estimate'];
        $nextEstimateDays = $row['next_estimate_days'];
        $notes = $row['notes'];

        $sqlQueryLastDate = "SELECT * FROM (select * from periods WHERE id < $id ORDER BY id DESC LIMIT 1) AS x ORDER BY id LIMIT 1";
        $resultLastDate = mysqli_query($conn, $sqlQueryLastDate);
        $resultCheckLastDate = mysqli_num_rows($resultLastDate);
        if ($resultCheckLastDate > 0) {
            while ($rowLastDate = mysqli_fetch_assoc($resultLastDate)) {
                $lastInDate = $rowLastDate['fell_in'];

                $sqlQueryCurrentDate = "SELECT * FROM (select * from periods WHERE id = $id ORDER BY id DESC LIMIT 1) AS x ORDER BY id LIMIT 1";
                $resultCurrentDate = mysqli_query($conn, $sqlQueryCurrentDate);
                $resultCheckCurrentDate = mysqli_num_rows($resultCurrentDate);
                if ($resultCheckCurrentDate > 0) {
                    while ($rowCurrentDate = mysqli_fetch_assoc($resultCurrentDate)) {
                        $currentOutDate = $rowCurrentDate['fell_out'];

                        $lastIn = new DateTime($lastInDate);
                        $currentOut = new DateTime($currentOutDate);
                        $intervalLastCurrent = $lastIn->diff($currentOut);
                        $elapsedLastCurrent = $intervalLastCurrent->format('%a days %h hours');
                        /*Why? Php is erasing everything after adding the above variable to the table...Entire first row gets erased!*/
                        echo "
                                <tr>    
                                    <td>".$id."</td>
                                    <td class='test'>".$elapsedLastCurrent."</td> 
                                    <td class='dateOutResult'>".$out."</td>
                                    <td class='dateInResult'>".$in."</td>
                                    <td class='sumHours'>".$sum."</td>
                                    <td class='nextEstimate'>".$nextEstimate." (".$nextEstimateDays.")</td>
                                    <td class='notes'>".$notes."</td>
                                </tr>";
                    } /*$sqlQueryCurrentDate*/
                }
            } /*$sqlQueryLastDate*/
        }
    } /*$sqlQuery*/
}
?>

这是实时结果: https : //unidrones.co.za/periods

我真的是mysql / php的新手,所以我不明白我在做什么错。 嵌套查询可能不是最好的使用方法,但是我仍在学习中,任何输入都会受到赞赏。

这是因为您的查询是//从ID <$ id的句点中选择* * ORDER BY ID DESC LIMIT 1; 您的第一个$ id将始终等于id。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM