Alechko Posted August 27, 2012 Share Posted August 27, 2012 Hi folks, I got a little confused about this problem. I am trying to make a views system for my website. I got a 770 rows of articles in my mySQL database and I'm trying to do a views system to know which article got the most views and when. (Today, 3 Days Ago, This week, This month) I tried to do something like this in mySQL database: Table: views ID articleID date But then I don't know how to sum it up? and If I will add column 'views' it wont help me because I have to change the dates all time. amm can someone advice me please? thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/267648-best-method-views-by-date/ Share on other sites More sharing options...
Christian F. Posted August 27, 2012 Share Posted August 27, 2012 It is quite simple, really. You only need to group the results by ID and use COUNT(*) to count the occurrences of each individual ID. SELECT COUNT(*),`id` FROM `views` GROUP BY `id`; Quote Link to comment https://forums.phpfreaks.com/topic/267648-best-method-views-by-date/#findComment-1372821 Share on other sites More sharing options...
Alechko Posted August 27, 2012 Author Share Posted August 27, 2012 Yes but how I will know to select by dates? to do something like: If '10-10-2010' AND articleID didn't exsits - Insert it... and if exists I need to update the views by one? Quote Link to comment https://forums.phpfreaks.com/topic/267648-best-method-views-by-date/#findComment-1372859 Share on other sites More sharing options...
Christian F. Posted August 27, 2012 Share Posted August 27, 2012 Sounds like you might need to check out a MySQL tutorial, and maybe the MySQL manual as well. The first request, at least, is basic SQL knowledge. The second request, not quite as basic, but still easily figured out if you had searched for "mysql insert or update". Quote Link to comment https://forums.phpfreaks.com/topic/267648-best-method-views-by-date/#findComment-1373011 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.