We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Obtaining percentages from channel entriesing percentages from channel entries

Development and Programming

jonathanmelville's avatar
jonathanmelville
132 posts
13 years ago
jonathanmelville's avatar jonathanmelville

I have built a customer survey for a client, just a SafeCracker form. They are wanting to have a simple stats page that shows some information about surveys that have been submitted.

An example: What percentage of respondents gave us a 5 rating?

This will tell me how many surveys have a 5 rating:

{exp:query sql="SELECT * FROM  `exp_channel_data` WHERE `channel_id` = '14' AND `field_id_30` = '5'"}{if count == total_results}{total_results}{/if}{/exp:query}

And this will tell me how many surveys have been taken:

{exp:stats channel="survey"}{total_entries}{/exp:stats}

So I have the 2 numbers I need to do the math, I just can’t make it process right. I have tried the exp:math plugin on devot:ee but I can’t make it work, probably because of parse order.

Does anybody have an suggestions? Thanks!

Jonathan

       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

Try something like this:

SELECT FLOOR(((COUNT(entry_id) / (SELECT COUNT(entry_id) FROM exp_channel_data WHERE channel_id = 14)) * 100)) AS percentage FROM exp_channel_data WHERE field_id_30 = 5 AND channel_id = 14
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.