1

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[1] < 7){
                echo $entry[1] . ' = Negative Feedback<hr>';
            }elseif($entry[1] > 8){
                echo $entry[1] . ' = Positive Feedback<hr>';
            }else{
                echo $entry[1] . ' = 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 Goosen May 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.

0

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

Then in your if statement:

if($entry[1] < 7){


//increment variable
$negative++;

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

//increment variable 
$positive++

echo $entry[1] . ' = Positive Feedback<hr>'; }else{ echo $entry[1] . ' = 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.