• Welcome to PHPVIBE Forums. Please log in.

[ Video Sharing CMS v4 ] Help Coding a user ranking page

Started by Rafa,

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RafaTopic starter

I want to have a user ranking page based on total views. For example:
user-A has 3 videos:

  • video 1 - 10 views
  • video 2 - 5 views
  • video 3 - 15 views
  • Total = 30 views

user-B also has 3 videos:

  • video 1 - 1 views
  • video 2 - 5 views
  • video 3 - 10 views
  • Total = 16 views

So, this means user-A is first and user-B is second. This would apply for all video under the user's id. That's the idea. I am thinking:

1. create a sql query (problably INNER JOIN) for the user/video tables;
2. create a loop to go through all videos where the user_id matches in both tables;
3. I will need two variables inside the loop.. one to store the result and another get the new value(then add it with the stored value);
4. Once it when through all videos for user one, store the value in the array variable for all users.
5. Create a final loop aiming to print and order the results in ascending fashion.

How does that sound? I won't be able to get to coding until the weekend, but I would appreciate a few suggestions or shortcuts for me to achieve my desired goal.

Thanks
  •  

PHPVibe A.

Why make it heavy?
Joins are heavy.


select
    sum(views) as total
from vibe_videos where user_id =


will return all the video views for the specific user's videos.

You can run it as an cron and update periodically. Or just update it once and then update the user field created to store the videos views on every insert.

Similar topics (7)