tapupartforpres Posted November 4, 2008 Share Posted November 4, 2008 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 More sharing options...
Michdd Posted November 4, 2008 Share Posted November 4, 2008 You could increment a field in the database for each question, then do some simple math to get a % for each answer. Link to comment https://forums.phpfreaks.com/topic/131403-sql-data-results-to-php/#findComment-682421 Share on other sites More sharing options...
Barand Posted November 5, 2008 Share Posted November 5, 2008 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? Link to comment https://forums.phpfreaks.com/topic/131403-sql-data-results-to-php/#findComment-682551 Share on other sites More sharing options...
tapupartforpres Posted November 5, 2008 Author Share Posted November 5, 2008 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!!! Link to comment https://forums.phpfreaks.com/topic/131403-sql-data-results-to-php/#findComment-683026 Share on other sites More sharing options...
Barand Posted November 5, 2008 Share Posted November 5, 2008 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. Link to comment https://forums.phpfreaks.com/topic/131403-sql-data-results-to-php/#findComment-683147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.