首页 > 解决方案 > php, $sql 在使用 $result 之前返回空的 $rows

问题描述

我是stackoverflow的新手,请不要急于我:)

我现在为此苦苦挣扎了几天:

    <?php
                require_once "../../config.php";
                $sql = "SELECT chestionar.participanti.id, chestionar.participanti.id_chestionar, chestionar.participanti.email, chestionar.participanti.nume
FROM chestionar.participanti WHERE chestionar.participanti.email LIKE '$email' LIMIT 1";
                if ($result = mysqli_query($link, $sql)) {
                    if (mysqli_num_rows($result) > 0) {
                        echo "<table class='table table-bordered table-striped'>";
                        echo "<thead>";
                        echo "<tr>";
                        echo "<th>IDClient</th>";
                        echo "<th>IDChestionar</th>";
                        echo "<th>Adresa</th>";
                        echo "<th>Nume</th>";
                        echo "<th>Actiuni</th>";
                        echo "</tr>";
                        echo "</thead>";
                        echo "<tbody>";
                        while ($row = mysqli_fetch_array($result)) {
                            echo "<tr>";
                            echo "<td>" . $row['id'] . "</td>";
                            echo "<td>" . $row['id_chestionar'] . "</td>";
                            echo "<td>" . $row['email'] . "</td>";
                            echo "<td>" . $row['nume'] . "</td>";
                            echo "<td>";
                            echo "<a href='deletech.php?id=" . $row['id'] . "' title='Sterge Client' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
                            echo "</td>";
                            echo "</tr>";
                        }
                        echo "</tbody>";
                        echo "</table>";
                        mysqli_free_result($result);
                    } else {
                        echo "<p class='lead'><em>No client.</em></p>";
                    }
                } else {
                    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                }

                mysqli_close($link);
                ?>

在任何东西被插入之前

<form action="" method="GET">
            <input type="text" placeholder="E-mail" name="search">&nbsp;
            <input type="submit" value="Search Client" name="btn" class="btn btn-sm btn-primary">
        </form>

它从 db 返回所有行,但为空。搜索有效。而且这种“异常”不适用于其他数据库。相同的服务器/相同的 mysql。谢谢。

标签: php

解决方案


Thank you for whoever posted. I found the problem, which was empty/null rows on selected columns. Once I've deleted those null rows, the problem disappeared.


推荐阅读