brown2005 Posted November 28, 2012 Share Posted November 28, 2012 $domain = 1; $user = 1; SELECT domains_ratings_domain, COUNT( * ) , AVG( domains_ratings_rating ) FROM domains_ratings WHERE domains_ratings_domain = $domain GROUP BY domains_ratings_domain I have this code which selects: domain 1 total number of ratings for domain 1 for all users average rating for domain 1 for all users what I also want to get is the rating that $user=1 has put in the table. Can this be done in the above code? or does it need to be separate? and how would I go about doing this please? Link to comment https://forums.phpfreaks.com/topic/271292-users-rating-total-count-in-table-avgratings/ Share on other sites More sharing options...
Barand Posted November 28, 2012 Share Posted November 28, 2012 nm - needs more thought Link to comment https://forums.phpfreaks.com/topic/271292-users-rating-total-count-in-table-avgratings/#findComment-1395932 Share on other sites More sharing options...
Barand Posted November 28, 2012 Share Posted November 28, 2012 try SELECT a.domains_ratings_domain, COUNT( * ) , AVG( a.domains_ratings_rating ) FROM domains_ratings a LEFT JOIN domain_ratings b ON a.domain_ratings_domain = b.domain_ratings_domain AND b.domain_ratings_userid = 1 WHERE a.domains_ratings_domain = $domain GROUP BY a.domains_ratings_domain Link to comment https://forums.phpfreaks.com/topic/271292-users-rating-total-count-in-table-avgratings/#findComment-1395981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.