sprintlife Posted September 17, 2008 Share Posted September 17, 2008 Hey IT programmers, I've been looking an basic setup for a counter system. I have a few different categories of items that I want to show it's hit rate. For example I wanna break it down like today's top hits (daily), past 7 days hits (weekly), Past 30 days (monthly), and total hits in all. My question is how should I record the data. Setup a table that records each hit and date it OR should I add 4 colums at the end of the items table so show daily, weekly, monthly, and total? If this question has been posted before sorry you may delete it, but just point me in the area where it's at. All I am trying to do is go with the best setup. Thanks ~Sprintlife Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 A DB table, or tables would be the way to go. I would suggest you use your lowest common denominator. If you wanted total hits, monthly hits, and daily hits, then your lowest is days. So, make your table with two columns; date and count. Then every time someone hits it, you can increment that day. Like this: $query = "SELECT \"count\" FROM hit_counter WHERE \"date\" = '".date('Y-m-d')."'"; // If you get a result, do an update. Otherwise do an insert // then you can do one of three selects: // for one day $query = "SELECT \"count\" FROM hit_counter WHERE \"date\" = '$date'"; // for one month $query = "SELECT SUM(\"count\") FROM hit_counter WHERE \"date\" BETWEEN '$startdate' AND '$enddate'"; // total $query = "SELECT SUM(\"count\") FROM hit_counter"; Quote Link to comment Share on other sites More sharing options...
sprintlife Posted September 17, 2008 Author Share Posted September 17, 2008 Thanks F1Fan for the fast reply. I believe you have helped me make up my mind on it. Let me break it down a little bit more. I have few 100 lets call them "items". I want a table on the homepage of the user's page showing what is the top 5 most viewed for the past day, then past 7 days, then past 30 days. So basically I need to setup another table contenting the following ( id, item id, time ). I just kind of worry doing that much pull from the database. Like if I had 10,000 users at once pulling that much data at a time. Should I need worry? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 17, 2008 Share Posted September 17, 2008 Are you really going to have 10,000 users online at any one time? I wouldn't worry. Quote Link to comment Share on other sites More sharing options...
sprintlife Posted September 17, 2008 Author Share Posted September 17, 2008 Right now I have about 1,500 users. This project is still in beta testing. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 As long as your web server and databases are set up to handle that load, it shouldn't be a problem. Quote Link to comment Share on other sites More sharing options...
sprintlife Posted September 17, 2008 Author Share Posted September 17, 2008 Okay thx! Now how do I post to say thread been helped? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 17, 2008 Share Posted September 17, 2008 Right now I have about 1,500 users. This project is still in beta testing. But there's a pretty big difference between 1,500 users and 1,500 concurrent users. Quote Link to comment Share on other sites More sharing options...
sprintlife Posted September 17, 2008 Author Share Posted September 17, 2008 I know what you mean. To give you an idea of the project it's for a school. Only way to get access to it is inside the school network. normal usage time will be 7am-4pm. 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.