いくつかのことを試しましたが、このコードをフィルター処理して、一度に 1 年分の番組のみを表示する方法が見つかりません。WHERE ステートメントと次のようなステートメントを追加しました。
DATE_FORMAT(show_date, '%Y') = 2013
しかし、何も機能していないようです。コードでエラーが発生し、何も表示されません...
$mostplayed = mysqli_query($con,"SELECT tbl_shows.song_id, tbl_songs.song_name,
count(tbl_shows.song_id) as cnt, MID(song_name,1,35) as short_name, tbl_shows.show_date
FROM tbl_shows LEFT JOIN tbl_songs
ON tbl_shows.song_id = tbl_songs.song_id
GROUP by tbl_shows.song_id
ORDER by count(tbl_shows.song_id) desc
LIMIT 5");
echo "<table style='float: left; height:150px; margin-right:30px;'>";
echo "<tr style='background-color:transparent;'>";
echo "<td>";
echo "<h4>Most Played Songs:</h4>";
while($row = mysqli_fetch_array($mostplayed))
{
echo $row['short_name'];
echo " (" . $row['cnt'].")</br>";
}
echo "</td></tr></table>";
コード自体は、Song を返し、その後に括弧内にカウントが続きます。song_date 年に基づいてデータを除外して、一度に 1 年だけを表示する方法を教えてもらえますか? ありがとうございました。どんな助けでも大歓迎です。
上記のコードは機能しますが、2 年間のすべてのデータを取得します... 以下のコードは何も返しません
SELECT tbl_shows.song_id, tbl_shows.show_date, tbl_songs.song_name,
count(tbl_shows.song_id) as cnt, MID(song_name,1,35) as short_name
FROM tbl_shows LEFT JOIN tbl_songs WHERE show_date BETWEEN '2013-01-01' AND '2013-12-31'
ON tbl_shows.song_id = tbl_songs.song_id
GROUP by tbl_shows.song_id
ORDER by count(tbl_shows.song_id) desc
LIMIT 5
すぐにいくつかのデータポイントをまとめます...