我试图从一个有 16k 行的表中获取 10 个结果。
此表中有一行称为视图,每次查看艺术家时都会获得 +1。但我得到意想不到的结果只有顶级艺术家。我为速度索引了视图行。我知道我必须循环它,但我不确定如何获取所有 10 行
我没有处理循环或一次获取多于一行的问题,需要帮助使用新的 mysqli 对其进行格式化
// Get Top Viewed Artist
$TopViewedArtist = mysql_query("SELECT * FROM `artists` ORDER BY `artists`.`views` DESC LIMIT 10");
$TopViewedArtistInfo = mysql_fetch_assoc($TopViewedArtist);
$TopViewedArtist_TotalRows = mysql_num_rows($TopViewedArtist);
print_r($TopViewedArtistInfo); // the data returned from the query
这是以可读格式显示艺术家姓名结果的解决方案。
$TopViewedArtists = mysql_query('SELECT * FROM `artists` ORDER BY `artists`.`views` DESC LIMIT 10');
while (($TopArtist = mysql_fetch_assoc($TopViewedArtists)) !== FALSE) {
//print_r($TopArtist);
echo $TopArtist['artist']; echo "<br>";
}
此代码可以为其他人更改。但需要更新到mysqli