我得到了這個非常奇怪的問題,警告:mysql_fetch_assoc()預計參數1是資源,鑑於空
Warning: mysql_fetch_row() expects parameter 1 to be resource, null given ...
不過,我檢查mysql_num_rows($結果),這是不爲0
echo '<h3>Comments</h3>';
$comment_query = "select * from comments where post_id='$post_id' order by comment_timestamp desc";
$comment_result = mysql_query($comment_query) or die(mysql_error());
if (mysql_num_rows($comment_result) != 0) {
while ($crow = mysql_fetch_assoc($commment_result)) {
$comment_username = $crow['username'];
$comment_text = $crow['comment_text'];
$comment_time = $crow['comment_timestamp'];
echo "<b>$comment_username </b><b>$comment_timestamp: </b> <br />".$comment_text."<hr /><br>";
}
} else { echo "No comments yet!"; }
有關於此的任何想法?我一直堅持一段時間,非常感謝您的幫助!
'commment_result'在'mysql_fetch_assoc'中有一個額外的'm'。 –
[mysql \ _fetch \ _array()/ mysql \ _fetch \ _assoc()/ mysql \ _fetch \ _row()的可能重複需要參數1爲資源或mysqli \ _result,布爾值給定](http://stackoverflow.com/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-expect-parameter-1-to) – aldrin27
謝謝@FrayneKonok,我真的有一個愚蠢的問題...... – Vicky