pianoman993 Posted October 25, 2009 Share Posted October 25, 2009 Hey everyone, I'm creating a site designed around users uploading music. How can I implement a system that would effectively record information such as view count so that a user could find the most viewed music of the day, of the week or of all time? Thank you so much in advance to anyone who might be of help! Mark Link to comment https://forums.phpfreaks.com/topic/178991-recording-popularity-by-day-week-all-time/ Share on other sites More sharing options...
joel24 Posted October 26, 2009 Share Posted October 26, 2009 you'd have a database with columns song_id, day_start, day_hits, week_start, week_hits, total_hits then run a script like the following for each time the song page is viewed... $song_id = 'the song id'; $sql = @mysql_query("SELECT * FROM song_hits WHERE song_id = $song_id"); $song_hits = mysql_fetch_row($sql); if ($song_hits['day_start'] == date('z')) { $sql_day = ' day_hits = ' . $song_hits['day_hits']++ . ', '; } else { $sql_day = ' day_start = ' . date('z') . ', day_hits = ' . $song_hits['day_hits']++ . ', '; } if ($song_hits['week_start'] == date('W')) { $sql_week = ' week_hits = ' . $song_hits['week_hits']++ . ', '; } else { $sql_week = ' week_start = ' . date('W') . ', week_hits = ' . $song_hits['week_hits']++ . ', '; } $sql_total = ' total_hits = ' $song_hits['total_hits']++; $sql = @mysql_query("UPDATE song_hits SET $sql_day $sql_week $sql_total WHERE song_id = $song_id"); Link to comment https://forums.phpfreaks.com/topic/178991-recording-popularity-by-day-week-all-time/#findComment-944368 Share on other sites More sharing options...
pianoman993 Posted October 26, 2009 Author Share Posted October 26, 2009 Thanks Joel! I'll definitely see what I can do with this Link to comment https://forums.phpfreaks.com/topic/178991-recording-popularity-by-day-week-all-time/#findComment-944400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.