# Get Gravity Forms field values and count how many? [closed]

I don't know how to explain this the best way. But, I am using a form in Gravity Forms for rating something 0 - 10. In the code below, I can get the results. However, I need to see how many ratings are 0-6 and how many ratings are 9-10. I have it so I can see the results and tell if it's "Negative", "Neutral", or "Positive" feedback. I need a count of "Negative" and "Positive" then pass those into the `\$neg_fb` and `\$pos_fb` variables, respectively. Hope this makes some sense.

``````<?php
// The form's ID
\$form_id = 7;

// Total Number of Entries
\$form_count  = RGFormsModel::get_form_counts(\$form_id);
\$entry_total = \$form_count['total'];
echo '<p>Number of entries: <strong>' . \$entry_total . '</strong></p>';

// Get Entry Values
\$entries = GFAPI::get_entries(\$form_id);
foreach(\$entries as \$entry){
if(\$entry < 7){
echo \$entry . ' = Negative Feedback<hr>';
}elseif(\$entry > 8){
echo \$entry . ' = Positive Feedback<hr>';
}else{
echo \$entry . ' = Neutral Feedback<hr>';
}
}

// NPS Variables
\$pos_fb = 2;
\$neg_fb = 1;
// NPS Formula
\$nps    = (\$pos_fb / \$entry_total) - (\$neg_fb / \$entry_total);
// Multiply for percentage
\$perct  = (\$nps * 100);
// Round up
\$whole  = ceil(\$perct);
// Display whole percentage
echo '<h4>' . \$whole . '% NPS Recommendation</h4>';
?>
``````

Can anyone help me out, or point me in the right direction?

## closed as off-topic by TheDeadMedic, Howdy_McGee♦, Robert hue, gmazzap♦, Pieter GoosenMay 27 '15 at 4:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

Set two variables to 0 before the foreach loop. \$positive = 0; \$negative = 0;

``````if(\$entry < 7){

//increment variable
\$negative++;

echo \$entry . ' = Negative Feedback<hr>';
}elseif(\$entry > 8){

//increment variable
\$positive++

echo \$entry . ' = Positive Feedback<hr>'; }else{ echo \$entry . ' = Neutral Feedback<hr>'; }
``````

Use the results as need.

• Thank you!! I had tried something similar before but I set the variables to 0 inside of the foreach statement. – user3571316 May 22 '15 at 2:19