我这里有一些PHP代码,它应该显示来自名为“Collections”的字段的唯一/ disctinct值。我已成功连接到其他地方的数据库。当这个PHP代码执行时,浏览器给我一个“警告:mysql_fetch_array():提供的参数不是第20行的mypage.php中的有效MySQL结果资源”
$id = isset($_GET['id'])?(int)$_GET['id']:0; // if $_GET['id'] exists, return it as an integer, otherwise use a sentinel, id's usually start with 1, so 0 works
if ($id!=0):
// I assume this is a specific news item meaning you know it's ONE result
$query = 'SELECT * DISTINCT (Collections) FROM Audios LIMIT 40'; // so try to use limit 1, no need to add extra steps in the database lookup
else:
$query = 'SELECT * DISTINCT (Collections) FROM Audios ORDER BY Collections DESC LIMIT 40';
endif;
$result = mysql_query($query);
;
// now loop through the results ***(This is Line 20)***
while ($row = mysql_fetch_array($result)){
// and use'em however you wish
echo '
<div>
<li><a href="#">'.$row['Collections'].'</a></p>
</div>
';
}
答案 0 :(得分:1)
SELECT DISTINCT (Collections) FROM Audios ORDER BY Collections DESC LIMIT 40
删除两个查询中的*。