Jump to content

SQL data results to php


tapupartforpres

Recommended Posts

Hello all.  Wondering if someone could lead me in the right direction.

 

I created a form with some radio buttons posting a value for that selection in a SQL database.  Well now they would like these items to be shown on a results page in percentages.  Pretty new to php so any help will be great.

 

I did check here, but couldn't find something specifically.  Thanks

Link to comment
https://forums.phpfreaks.com/topic/131403-sql-data-results-to-php/
Share on other sites

You need two values to calculate a percentage (X as a % of Y)

 

So, are you saying you have the radio buttons

 

( ) 1    ( ) 2  ( ) 3

 

and you want the percentage of those selecting 1, 2 or 3  from the total entries?

Ok sorry like I said I'm new here.

 

One of my questions has 12 questions and each question has a "very satisfied" to a "very dissatisfied" radio button that gives the result of 1 - 5.  I probably did this the wrong way, but for each question within a question I set up something like this and put it into it's own SQL field:

 

$q2_1=mysql_real_escape_string($_POST['q2_1']);

 

I guess that doesn't matter, but see I am not sure.  Help!!!

First you need a count of the total responses.

 

$res = mysql_query ("SELECT COUNT(*) FROM tablename");
$count = mysql_result($res, 0);

 

Now you need to count each value, 1-5, and divide by the count/100 to get the percent.

 

How you do that query depends on how you are storing the data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.