helpmeplease2 Posted February 9, 2008 Share Posted February 9, 2008 How can I do this? I want to keep track of the most viewed games on my website (www.gameanyone.com) I can guess that you add some $b=$a+1; and then insert the $b.. but that would only count views. How can I count the number of views in the last week or better the last 7 days? Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/ Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 <?php $period = 604 800; // Seconds in a week $query = "SELECT * FROM `table` WHERE `date` < '".(($now = time()) - $period)."'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ "Views:" . $row['views'] . "<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462665 Share on other sites More sharing options...
helpmeplease2 Posted February 9, 2008 Author Share Posted February 9, 2008 So I am using this to get the number of views in a week... but do I set 'date' as a normal 'date' type in phpmyadmin? And I don't see how it would know when the views were viewed unless it logged each view in it's own row. <?php $period = 604800; $query = "SELECT * FROM `games` WHERE `date` < '".(($now = time()) - $period)."'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $views=$row['views']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462819 Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 the date has to be a TIMESTAMP Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462840 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 getting back to your original question every time a game is "viewed" add a row to a mysql table called Game Views Then Just find the COUNT('Game_Views'), Game_Name from `table` where Date_Played <= NOW()-64000 and you have it. Probably a good Idea to flush this every so often as it could get huge. Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462854 Share on other sites More sharing options...
helpmeplease2 Posted February 9, 2008 Author Share Posted February 9, 2008 I'm thinking I don't want to count them like that, as yes it will get huge. The first day there would be over a million entries. Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462923 Share on other sites More sharing options...
cooldude832 Posted February 10, 2008 Share Posted February 10, 2008 then you don't have a "Good" continuous method you will need to do something that counts the number of hits for each game on each day and simply do addition to that count GameName Day Hits and then add up the counts for each game in the given Days frame (Or week) Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462924 Share on other sites More sharing options...
phpSensei Posted February 10, 2008 Share Posted February 10, 2008 Like Cooldude said, and delete all single weekly hits that are older then 1 week... or just use the method we posted with the query. I suggest you make a table called "Weekly Views" and as cooldude said: GameName Day Hits Quote Link to comment https://forums.phpfreaks.com/topic/90231-most-viewed-in-1-week-time-period/#findComment-462972 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.