Quantcast
Channel: Topics in Category: Can I do this with LimeSurvey? - LimeSurvey forums
Viewing all articles
Browse latest Browse all 17529

Query the hosted LimeSurvey sql database - by: Joffm

$
0
0
Hi,
here is an API script to get the entire survey data.
<?php
 
require_once 'jsonrpcphp/JsonRPCClient.php';
 
define( 'LS_BASEURL', 'https://www.example.com/survey');  // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myUserName' );
define( 'LS_PASSWORD', 'myPassword' );
 
// the survey to process
$survey_id=mySurvey_ID;
 
// instantiate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
 
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
if(is_array($sessionKey))
{
    header("Content-type: application/json");
    echo json_encode($sessionKey);
    die();
}
 
/* Get the responses */
$response = $myJSONRPCClient->export_responses(
    $sessionKey,
    $survey_id,
    'json', // Document type : pdf,csv,xls,doc,json
    null, // Language code : null : default from survey
    'complete', // Stautus complete|incomplete|all
    NULL, // Heading : code|full|abbreviated : question text, default code
    'short', // answer : short|long , default : long
    2,  // First exported SAVEDID   or NULL
    3  // Last exported SAVEDID   or NULL
    ); 
 
$decodedString = base64_decode($response);
$aResponses = json_decode($decodedString, True);
 
// Find the first response ID
$aFirstResponse = reset($aResponses['responses'][0]);
 
echo '<table style="border-collapse: collapse; text-align: left;">';
echo '<tr>';
// Insert column headers
foreach($aFirstResponse as $key => $value) {
	echo '<th style="border: 1px solid #CCC; padding: 2px 7px;">'.$key .'</th>';
}
echo '</tr>';
 
foreach($aResponses['responses'] as $key => $row) {
//echo "Key: ".$key."  Row: ".$row;
	echo '<tr>';
	// Insert the data
	foreach(reset($row) as $key => $item) {
 		echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">'.$item .'</td>';
	}
	echo '</tr>';
				}
echo '</table>';
 
 
 
// release the session key
$myJSONRPCClient->release_session_key( $sessionKey );
 
 
?>

See here:
https://api.limesurvey.org/classes/remotecontrol_handle.html#method_export_responses




Joffm


Or you do it with direct access in php.
It is not to difficult to include a mapping table (SGQA-Codes -> question text)

And it's always better to open a new thread than to continue such an old one.
I am really sure Jjamison0221 is looking into the forum and will not be able to answer your question.

Viewing all articles
Browse latest Browse all 17529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>