我在这里有一些 php 代码,应该显示来自名为“集合”的字段的唯一/不同值。我已成功连接到其他地方的数据库。当这个 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>
';
}