gpt4 book ai didi

php - 获取 Mysql $Row 和查询

转载 作者:太空宇宙 更新时间:2023-11-03 11:41:46 25 4
gpt4 key购买 nike

我编写了这段代码来获取前 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"] 丢失了,在我看来我必须进行另一个查询,我的问题是我可以在现有查询中加入它吗?

最佳答案

也许你应该这样做

$mysqli_query ="SELECT id,page, count( * ) AS 'Cnt'
FROM pageview
GROUP BY page
ORDER BY `Cnt` DESC
LIMIT 5 ";

关于php - 获取 Mysql $Row 和查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41207629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com