Check out the LimeSurvey source code on GitHub!

Get results of an individual survey response

5 years 5 months ago #63866 by raaboo

I am running LimeSurvey for the purpose of creating audits - each audit is run once using a specific token and the results are then made available to the inspector using fusioncharts - this is where I have a problem!

Because LimeSurvey uses the Survey ID, GroupID and QuestionID as column names I need to find a way of getting the assessment values from each column and then calculating teh overall score - for exampl, it is easy to do a "SELECT lime_answers.assessment_value FROM lime_answers, lime_survey_12345 where lime_answers.code = lime_survey_12345.12345X123X1#1 AND lime_survey_12345.token = ABCDEFG" to get the Assessment value of the response chosen for a single question - but I do not want to have to run one query over and over again to get teh assessment values of each question answered - this will hammer my server and cause access to be restricted as it's shared hosting.

How can I get a SUM of the assessment values for all questions answered that have a question ID ending in #1? I have looked at various PHP options and through all the documentation, but can find nothing about how to get assessment values for a single response from the survey.

Hopefully this all makes sense - basically i am trying to be able to run assessments on a single survey response without having to run the same mySQL query over and over again - has anyone else managed this?

Please Log in to join the conversation.

5 years 5 months ago #63867 by raaboo

So i figured a workaround in PHP and hopefully thsi will help someone else out...
$query = "SELECT
WHERE = 2";  
  $strQuery = $query;
    $result = mysql_query($strQuery);
	$result2 = mysql_fetch_array($result);
	foreach($result2 as $k => $v){
	if (substr($k, -2) == '#1') { if (is_null($v)){}else{
		$scorequery = 'select lime_answers.assessment_value, lime_answers.`code` from lime_answers where lime_answers.`code` = "'.$v.'"';
		//echo "SCORE QUERY: ".$scorequery." FOR :".$k."<br/>";
	$addition = mysql_query($scorequery) or die(mysql_error());
	if (mysql_num_rows($addition)== 0) {}else{
	$score = $score + mysql_result($addition, 0, 0);
	$possible = $possible +4;}}}
	//echo $score."<br/>";
	$total = round($score/$possible, 2)*100;

What this does is basically pull all the fields and columns from the survey results table (lime_survey_62388 in the query), then iterates them in to an array, goes through the array keys to find ones that end with "#1" - this can be amended to anything or removed altogether, then it runs another query to get the assessment value for each answer, adds these together at the same time as adding '4' to teh total 'possible' score, then outputs a percentage value.

This is very heavy on mysql so any way to trim this down is much appreciated but hopefully this will be a start for someone else

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form