當從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)。 –