当从fetch_assoc回显结果时,我希望跳过空(NULL)结果。 现在我的代码是:php fetch_assoc跳过空结果
while ($rowsoft = $resultsoft->fetch_assoc()) {
echo "<table class='swtable' cellspacing='0' summary='Software table'>
<tbody>
<tr><td class='software_up'><a class='sw' href='software.php?id=" . $rowsoft['id'] . "'>" . $rowsoft['title'] . "</a></td></tr>
<tr><td class='software'><div class='tags'>Tags: </div><a class='tags' href='#'>" . $rowsoft['tag_1'] . "</a>
<a class='tags' href='#'>" . $rowsoft['tag_2'] . "</a><a class='tags' href='#'>" . $rowsoft['tag_3'] . "</a></td></tr>
}
但并不总是存在于$结果rowsoft [ 'TAG_1']或$ rowsoft [ 'TAG_2']或$ rowsoft [ 'tag_3']。 如何更改fetch_assoc()内部的回显以使其仅在存在结果时才起作用? 或者我应该使用foreach还是其他的东西?
谢谢
为什么不在SQL查询中排除它们 – Musa
从SQL中排除它们很容易,但是例如 ...仍然会被回显。如果没有SQL结果,我不希望它被回显 – phantomlord
如果你解决了这个问题,请不要在问题的标题上附加*“solve”*,但考虑[接受一个答案](http:// meta .stackexchange.com/a/5235/224130)。 –