Jump to content

turning results into percentages with a simple query


hopeless

Recommended Posts

I have aquired a ready made Db and scripts to get the results out but they way the script gets the results at the moment appears very inefficient and there has to be a better way but I can't think of it.  I can not rebuild the Db as the results are already in it, I need to get them out in a more efficient manner.

It is for a site user survey, 7 questions, each with 3 or more options, all answers are stored as  numerical representing the different options, each question has a single column in the table with it's answers within that column. I need to get a percentage figure for each possible option for each question.

The current script queries the db seperately for each option of each question - a total of 26 seperate queies over the 7 questions, using a

[code]$onea= mysql_query("SELECT one FROM survey where one=1");
$numrows = mysql_num_rows($onea);
if ($numrows == 0){
     echo("No results found matching your query - $query");
     exit();}
else{
$onea_result = $numrows;}
$onea_pc = ($onea_res / $last) * 100;
$onea_final = sprintf("%0.2f", $onea_pc);

$oneb= mysql_query("SELECT one FROM survey where one=2");
$numrows = mysql_num_rows($oneb);
if ($numrows == 0){
     echo("No results found matching your query - $query");
     exit();}
else{
$oneb_result = $numrows;}
$oneb_pc = ($oneb_res / $last) * 100;
$oneb_final = sprintf("%0.2f", $oneb_pc);
[/code] query format - changing the $onea= mysql_query("SELECT one FROM survey where one=1"); for each query ie onea to oneb, onec etc and then using twoa, twob, twoc and so on.

Please can someone point me in the right direction to making this work with one query for each Q or less even as I am totally bamboozled.
Link to comment
Share on other sites

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.