php - 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">
<input type="submit" value="Search Client" name="btn" class="btn btn-sm btn-primary">
</form>
它从 db 返回所有行,但为空。搜索有效。而且这种“异常”不适用于其他数据库。相同的服务器/相同的 mysql。谢谢。
解决方案
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.
推荐阅读
- spring-kafka - Spring Cloud Stream v/s Spring for Apache Kafka
- php - 在每个 10 的倍数中设置一个新变量,没有限制
- google-apps-script - 需要复制单元格颜色并在 EMAIL 正文中发送
- batch-file - 使用命令提示符(命令)调整窗口/应用程序的大小?- (.bat 文件)
- python - 如何将 Numpy 数组沿轴 0 划分为大小相等的 numpy 数组列表?
- sql - 如果另一个表中没有匹配的 id 则生成一行作为占位符行
- javascript - 如果在地图或推送或其他内容中出现条件
- python - Python比较没有返回匹配2个相同的字符串
- python-3.x - 可能的 if/elif 语句错误
- python - 从 .json 文件中获取数据时,“元组”对象没有“格式”属性