hopeless Posted January 23, 2007 Share Posted January 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
artacus Posted January 23, 2007 Share Posted January 23, 2007 [code]SELECT one, COUNT(survery.*) AS cntFROM surveyWHERE one IS NOT NULL GROUP BY one[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.