+ Reply Thread
#1

Am using on Fivestar Module for a review website. what i need is something like the wordpress ratingĀ where you have those who total number of those who vote for different star. I have gone through the field database and the values of each star vote is 20, 40, 60, 80, 100.

My Use case are these

1 => Pull Data out from `votingapi_vote.value` like

$query = db_select('votingapi_vote', 'rate');
$query->condition('rate.entity_type', 'node');
$query->condition('rate.entity_id', $nid);
$query->condition('rate.tag', 'perforate');
$query->condition('rate.value', '60'); //**This line will pull ONLY 3 star votes '20' will be 1 star
$query->addField('rate', 'uid');

$thee_stars = $query->countQuery()->execute()->fetchField(); // execute and count occurrence 
print "??? => " . $thee_stars;

**With above how can I repeat for 20, 40, 60, 80, 100 without having to duplicate the code above for 1 star, 2 star etc

---

2 => Pull Data out from `field_data_field_speed.field_speed_rating` I need to run Query like this

$query3 = db_select('comment', 'c');
$query3->join('field_data_field_speed', 'f', 'c.cid = f.entity_id');
$query3->fields('f', array('field_speed_rating'));
$query3->addExpression('sum(field_speed_rating)', 'total');
$result = $query3->execute()->fetchAssoc(); print($result[total]);
How do i do same for other fields (about 19) without copy and pasting. If you have other better method please share

Other field tables are likeĀ field_data_field_herodyn, field_speed_herodyn

#2

This dude really mean business o, e don tale small wey i do this drupal something o.

#3

I just realize am not thinking like a coder, I could wrap the whole code with a function and pass the tbl_name and field as parameter.

Back to top