Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Display responses from my survey in real time via PHP or HTML

More
7 years 4 months ago #185067 by tpartner
Can you attach a small sample survey (.lss file) and your complete code (excluding credentials) in the PHP file?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 4 months ago #185143 by h0rr0rOrg
Thanks, Tony. I've attached the .lss and input the PHP code below.

I hope you can see what I'm missing!

File Attachment:

File Name: limesurvey...7824.lss
File Size:96.45 KB

Code:
<html> <head> <title>HWA Bram Stoker Award Recommendations</title> <script language="JavaScript" type="text/JavaScript"> // THE FOLLOWING IS LIMESURVEY CODE function get_session_key(USERNAME $username, PASSWORD $password) </script> </head> <body> <!-- START OF CONTENT --> <table border=1><tr bgcolor="#bbbbbb"><td colspan=8><br><center><h1>HWA Bram Stoker Award&reg; Member Recommendations for Works Published in 2018</h1> <h2>ANTHOLOGY CATEGORY</h2> <?php require_once 'jsonrpcphp/JsonRPCClient.php'; define( 'LS_BASEURL', 'https://horror.limequery.com'); // adjust this one to your actual LimeSurvey URL define( 'LS_USER', 'USERNAME' ); define( 'LS_PASSWORD', 'PASSWORD' ); // the survey to process $survey_id=977824; // 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 ); // print_r($sessionKey ); if(is_array($sessionKey)) { header("Content-type: application/json"); echo json_encode($sessionKey); echo '<br />This is another test with sesssion key.<br />'; die(); } else if($sessionKey) // Is a valid session { /* Get the responses */ $rawResponses = $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 'code', // Heading : code|full|abbreviated : question text, default code 'short', // answer : short|long , default : long null, null, ['submitdate','lastpage','id','title','author','publisher','category'] ); if(is_array($rawResponses)) { // Oops, print any errors print_r($rawResponses); } else { // There is a valid response... // Decode the retuned base-64 string and convert to an array $decodedString = base64_decode($rawResponses); // The decodedString variable turns the data into an array and contains the entire array of data for the survey in English $responseArr = json_decode($decodedString, True); // Creates the json-decoded array of data for use in PHP. echo '<table border=1 text-align="left">'; echo '<tr>'; // Insert column headers_list foreach($responseArr as $key => $value) // $responseArr is the entire array, $key returns the name of the data set 'responses'; $value returns an array of the jSon data pairs with => between { foreach($responseArr['responses'] as $rownumber => $row) // $rownumber is a numeric value, not an array; $row is an array of all data in each submission. { echo '<tr>'; // Inserts the data foreach(reset($row) as $category => $item) // $key returns the category name, $item returns the data associated with the category, one item at a time { // THE FOLLOWING LINE IS WHERE I NEED TO ECHO ONLY SPECIFIED $item DATA echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">A: ' . $item . '</td>'; } } } echo '</tr></table>'; } } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?> </td></tr></table> <!-- END OF CONTENT --> </body> </html>
The topic has been locked.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose