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 Quote Link to comment 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"); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.