daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $mostviewed_query = "SELECT p.id, COUNT(v.target) AS number_of_views FROM ".TBL_PROFILES." AS p LEFT JOIN ".TBL_VIEWS." AS v ON (p.id = v.target) WHERE DATE_SUB(NOW(),INTERVAL 7 DAY) >= v.timestamp GROUP BY p.id ORDER BY number_of_views DESC LIMIT 5";
  2.  
  3. Above query shows the list:
  4.  
  5. Profile 2 - Views: 8
  6. Profile 3 - Views: 5
  7. Profile 1 - Views: 4
  8. Profile 4 - Views: 3
  9. Profile 5 - Views: 2
  10.  
  11. $popular_query = "SELECT p.id, COUNT(v.target) AS number_of_views FROM ".TBL_PROFILES." AS p LEFT JOIN ".TBL_VIEWS." AS v ON (p.id = v.target) LEFT JOIN ".TBL_SLIDES." AS s ON (p.id = s.profile_id) WHERE DATE_SUB(NOW(),INTERVAL 7 DAY) >= v.timestamp GROUP BY p.id ORDER BY number_of_views DESC LIMIT 5";
  12.  
  13. Above query shows the list:
  14.  
  15. Profile 2 - Views: 8
  16. Profile 1 - Views: 4
  17. Profile 4 - Views: 3
  18. Profile 5 - Views: 2
  19. Profile 6 - Views: 1
  20.  
  21. "Profile 3" has mysteriously disappeared. Even though it should be the same list. All I'm doing in the second query, is to combine TBL_SLIDES table, to get that data.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top