我从服务器获取数据。我希望该用户可能只获得表格中的最后5条记录。
这是我目前使用的查询;它不起作用:
$query = mysql_query("
SELECT
ml.PostID,
ml.UserID,
ml.PostDate,
ml.PostTime,
ml.PostCategory,
ml.PostSubCategory,
ml.PostComments,
cat.UserName
FROM UserPosts AS ml
LEFT JOIN UserNames cat
ON cat.UserID = ml.UserID
ORDERD BY DESC LIMIT 5");
给出以下错误
警告: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/getPosts.php on line 77
答案 0 :(得分:1)
按顺序
添加列名SELECT ml.PostID,
ml.UserID,
ml.PostDate,
ml.PostTime,
ml.PostCategory,
ml.PostSubCategory,
ml.PostComments,
cat.UserName
FROM UserPosts AS ml
LEFT JOIN UserNames cat
ON cat.UserID = ml.UserID
ORDER BY ml.PostComments DESC
LIMIT 5
答案 1 :(得分:0)
$sql = 'SELECT ml.PostID,
ml.UserID,
ml.PostDate,
ml.PostTime,
ml.PostCategory,
ml.PostSubCategory,
ml.PostComments,
cat.UserName
FROM UserPosts AS ml
LEFT JOIN UserNames cat
ON cat.UserID = ml.UserID
ORDER BY ml.PostTime DESC LIMIT 5';
$query = mysql_query($sql) or die(mysql_error());
试试这个。