Notifications
Clear all

Linking up reviews received and reviews given.

18 Posts
3 Users
0 Reactions
4,659 Views
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

Hey,

I'm using this query to find the number of reviews written and the reviews received for one person:

SELECT COUNT(s.reviews) as r, (SELECT COUNT(reviewid) as num FROM fanfiction_reviews WHERE uid = '1') as g FROM fanfiction_stories as s JOIN fanfiction_reviews as r ON s.sid = r.item AND r.type = 'ST' WHERE s.uid = '1'

I'm wondering -- how would/could I amend it so it would rely on a LIMIT i.e. an "omnisicent"-esque look of EVERYONE's reviews written/received for an admin browse?


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 17/02/2010 9:17 am
(@tammy)
Posts: 2577
Member Moderator
 

You mean like a custom members list option?  For something like that wouldn't you want one or the other so you'd only have 1 number after the name?  I think what you are asking for is "GROUP BY"


SELECT COUNT(reviewid), uid FROM PREFIXfanfiction_reviews WHERE review != 'No Review' GROUP BY uid


 
Posted : 17/02/2010 1:50 pm
(@tammy)
Posts: 2577
Member Moderator
 

You don't have anyone reviewing series or coauthors?


 
Posted : 17/02/2010 1:50 pm
(@lyndsie)
Posts: 1263
Member Moderator
 

I'm helping at the site I think she wants this for. There's a contest thing going and they want to be able to compare the number of reviews someone gets to the number they leave in one glance. Coauthors is turned off and reviews can't be left for series.


 
Posted : 17/02/2010 4:43 pm
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

I'm helping at the site I think she wants this for. There's a contest thing going and they want to be able to compare the number of reviews someone gets to the number they leave in one glance. Coauthors is turned off and reviews can't be left for series.

Yup. : )


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 17/02/2010 5:12 pm
(@tammy)
Posts: 2577
Member Moderator
 

Did you modify your site then because you CAN leave reviews for series by default.


 
Posted : 17/02/2010 6:20 pm
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

We haven't... but we could. Idk. Would that make the code harder? I presume we'd just get rid of the type = 'ST'. :S


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 17/02/2010 7:18 pm
(@tammy)
Posts: 2577
Member Moderator
 

Well by putting in type = 'st' you're limiting it to only reviews of stories.  So if someone has reviewed a series that review isn't being counted.  Do you allow round robins?  That could also throw your numbers off.  The reviews given isn't the problem, it's the reviews received.  So what are you trying to compare here with the given and received?    Just looking at the two numbers doesn't really tell you much I would think...there'd be too many to really grasp just by looking at a members page.  I assume you're trying to rank them somehow. 


 
Posted : 17/02/2010 7:40 pm
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

Presently, we have a panel in for the Account which lists the code in the first post. It basically shows the numbers of reviews the person has given and the number of reviews a person has received. We're using in conjunction with a "game" we're playing -- the idea is to balance your reviews written and received (i.e. for every twenty reviews you receive, you write twenty for other people). At the moment, because it only shows the member their figures it means that it's only they who know if they've "balanced" or not. We were wondering if it was possible to "link" the two numbers and output an admin-y list where we could see everyone's figures instead of going through the "WHERE uid = '$id'" route.

Is that possible? If we're just thinking of solely of story reviews and disregarding round robins/series.


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 17/02/2010 7:54 pm
(@tammy)
Posts: 2577
Member Moderator
 

Hmm...The authors.php page won't let you have two numbers. It's set up only to include the count of the stories.  How many members do you have?  If it's not many, you can probably get away with just a straight list using a custom page.  If it's a lot, you might want to make a copy of includes/memberslist.php and modify it to output the 2 numbers instead of the story count.I think you'll need to break your original query into 2 queries then use an array to join the results. Pseudo-code as follows:


$reviews = dbquery("SELECT COUNT(reviewid) as reviews, uid FROM PREFIXfanfiction_reviews WHERE review != 'No Review' GROUP BY uid");
while($r = dbassoc($reviews)) {
   $reviewers[$r['uid']] = array("reviews" => $r['reviews']);
}
$revreceived = dbquery("SELECT count( reviewid ) AS rec, s.uid FROM fanfiction_reviews AS r, fanfiction_stories AS s WHERE r.type = 'ST' AND r.review != 'No Review' AND r.item  = s.sid GROUP BY s.uid");
while($r = dbassoc($revreceived)) {
  $reviewers[$r['uid']]['rec'] = $r['rec'];
}
foreach($reviewers AS $k => $v) {
   if(empty($v['reviews'])) $reviewers[$k]['reviews'] = 0;
   if(empty($v['rec'])) $reviewers[$k]['rec'] = 0;
   $reviewers[$k]['diff'] = $reviewers[$k]['reviews'] - $reviwers[$k]['rec'];
}

And somewhere in there you'll need to throw in a link to the author table to get the username.  Possibly in both queries to make sure you get a username if someone has received but not given or given but not received.

Edited to clean up my mess.


 
Posted : 17/02/2010 8:38 pm
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

Ooo. Thank you very much! I'll tinker with it and post up my results later.

ETA: I've got it to work. Yay. I'm wondering if it's possible to paginate arrays... I omitted reviewers with zero reviews to try and keep numbers low. I'm guessing DB pagination is going to be super tricky because the numbers in the database won't match up...


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 17/02/2010 9:17 pm
(@tammy)
Posts: 2577
Member Moderator
 

Notice I also put the difference in there.  You could use that to provide a ranking.


 
Posted : 17/02/2010 10:01 pm
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

That was an idea, but I can't get the array to sort itself using the diff key. o.O


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 17/02/2010 10:46 pm
(@tammy)
Posts: 2577
Member Moderator
 

No you'd have to create a separate array for it. Change:


$reviewers[$k]['diff'] = $reviewers[$k]['reviews'] - $reviwers[$k]['rec'];

$ranked[$k] = $reviewers[$k]['reviews'] - $reviwers[$k]['rec'];

And then sort it using asort


asort($ranked);

Then use the 2 arrays together to show the rankings. Pseudo code below assumes you added username to the reviewers array.


$x = 1;
foreach($ranked AS $k => $v) {
  $output .= "$x. ".$reviewers[$k]['username']." ".$v."<br />";
  $x++;
}


 
Posted : 17/02/2010 11:09 pm
(@lyndsie)
Posts: 1263
Member Moderator
 

Huh. I didn't know you could leave reviews for series! Learn something new every day.


 
Posted : 17/02/2010 11:50 pm
Page 1 / 2
Share: