-1

「ニュースと更新」の簡単なスクリプトを作成しました

私のクエリは次のとおりです。

$query = mysql_query("SELECT * FROM a_commants WHERE postid='$postid' ORDER BY id DESC LIMIT 0,10");

最後のコメントを表示します

すべてのコメントまたは少なくとも 10 個のコメントを表示するようにしたい

私はそれを変更した場合:

$query = mysql_query("SELECT * FROM a_commants WHERE postid='$postid'");

最初のコメントのみを表示します

どうしたの?:(

4

1 に答える 1

2

I think that the problem is in your php code, not MySQL. The query seems fine, as long as you have more than one comment, but it seems that you are not iterating through results, just printing the first row you get from db.

This should show last 10 comments:

$res = mysql_query("SELECT * FROM a_commants WHERE postid='$postid' ORDER BY id DESC LIMIT 0,10");
while($row = mysql_fetch_array($res)){ // iterate through results
    print_r($row); // print the row
}

And you should definitely switch to mysqli or PDO, and sanitize your inputs. The mysql_* functions are deprecated and going to be removed from PHP.

于 2013-09-06T11:14:02.033 に答える