- Posts: 16
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$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, null ); 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 $headinng => $item) // $heading returns the heading name (of which 'category' is one), $item returns the data, one item at a time { // THE FOLLOWING line is where I need to echo only specified $item data, and if I can nest those criteria, all the better. I need to filter first by $item (APPROVED), then filter by multiple other $items (AUTHOR and TITLE) to choose which to show. echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">' . $item . '</td>'; } } }
$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 NULL, // answer : short|long , default : long 1, 3, ['id','token','submitdate','lastpage'] );
['submitdate','lastpage','id','title','author','publisher','category']
echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">A: ' . $item . '</td>';
<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>