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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.