Jump to content

Recording popularity by day, week.. all time?


pianoman993

Recommended Posts

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

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.