Jump to content

Recommended Posts

I've been trying to do this for a while now, and it's to the point I have to figure this out. I have a comm_rating (comment rating). values are 3=positive, 2=neutral, 1=negative. I don't want to put neutral comments since to me those don't show dissatisfaction. I am trying to take all comm_rating with 3 or 1 and fully calculate the percentage of positive feedback. Kind of like how eBay does it. I just can't figure this out.

 

What i have found out...

 

commCount3 and commCount1 are querys to figure out total of 3 or 1 ratings on a certain person.

 

$totalPoints = $commCount3 - $commCount1;

$allPoints = $commCount3 + $commCount1;

$percent = ($totalPoints) / $allPoints * 100;

 

if 3=26 and 1=6 I get a percentage of 58.6206896552

 

for some reason this doesn't seem like it is right. I'm not sure if I doing my math wrong or what. Also I just want the 58 not all the .620...

Link to comment
https://forums.phpfreaks.com/topic/52854-solved-finding-a-percentage/
Share on other sites

You need to include the neutral count in the total to get the true %age of positive responses

 

[pre]

                            $count3

$pos_pcent =    ---------------------------  * 100

                $count3 + $count2 + $count1

[/pre]

Thing is, I'm not trying to even count the neutrals. A neutral is neither good or bad.

 

Thus, EKINdesigns posted something that works perfectly and does return the right percentage.

 

if count3 and count1 = 29

count3 = 23

count1 = 6

rounded percentage is 79% which is right. Thank a bunch.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.