未显示第一行html行 [英] The first html row is not being displayed

查看:75
本文介绍了未显示第一行html行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So, let’s say I have 10 rows in my database. However, after the mysql query, only 9 rows are being displayed in the html table. I need every row from the database to be displayed in the html table.

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

I hope someone can point me in the right direction. I’ll be here if I need to provide anymore details.

这是我的代码:

<?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的新手,所以我不明白我在做什么错.嵌套查询可能不是最好的使用方法,但我仍在学习中,任何输入都会受到赞赏.

I am really new to mysql/php so I do not understand what I'm doing wrong. The nested queries is probably not the best approach to use, but I'm still learning, and any input will be deeply appreciated.

推荐答案

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

This is because your query is //select * from periods WHERE id < $id ORDER BY id DESC LIMIT 1; your first $id will be always equal id.

这篇关于未显示第一行html行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆