【发布时间】:2016-06-09 12:38:39
【问题描述】:
我正在查询一个数据库,但是当结果为空时,我想输出一个表行,显示“无显示”,但 if 似乎总是返回 true。
这是我的代码...
$priorityincidentsQ = mysql_query("SELECT * FROM applications WHERE pi >= ('2') ");
while($priorityincidentsR = mysql_fetch_object($priorityincidentsQ))
{
if (empty($priorityincidentsR)) {
echo "<tr><td class=\"closedcallscell centered\"><b>Nothing to display</b></td></tr>";
} else {
echo "<tr><td class=\"closedcallscell\"><b>$priorityincidentsR->application_friendly_name</b></td>";
echo "<td class=\"closedcallscell table_row_small\"><center>$priorityincidentsR->pi</center></td></tr>";
}
}
【问题讨论】:
-
您是否尝试过 var_dump 的 priorityincidentsR 值?
-
代码执行后您的表格究竟显示了什么?从理论上讲,如果您的结果由于 while 循环上的条件而没有返回任何行,那么您的 if 语句甚至永远不会运行。如果没有行,则
mysql_fetch_object()不会被评估为真。如果您根本看不到 if 语句的结果,那么您的查询一定有错误。
标签: php mysql if-statement while-loop