我已经制作了这段代码来获得前5首歌曲的观点:
$mysqli_query ="SELECT page, count( * ) AS 'Cnt'
FROM pageview
GROUP BY page
ORDER BY `Cnt` DESC
LIMIT 5 ";
$result = mysqli_query($conn, $mysqli_query) or die (mysqli_error($conn));
$num_rows = mysqli_num_rows($result);
echo "<br>Top 5 Song views:<br>";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo " <a href=/songs.php?id=".$row["id"]." target=\"_blank\">" .$row["page"]."</a><br />";
}
} else {
echo "0 results";
}
//fim
mysqli_close($conn);
?>
它正在运行,但是$ row [“id”]丢失了,在我看来我必须再做一个查询,我的问题是我可以在现有查询中加入吗?
答案 0 :(得分:3)
也许你应该这样做
$mysqli_query ="SELECT id,page, count( * ) AS 'Cnt'
FROM pageview
GROUP BY page
ORDER BY `Cnt` DESC
LIMIT 5 ";