- Posts: 16
- Thank you received: 0
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
- h0rr0rOrg
- Topic Author
- Offline
- New Member
Less
More
4 years 9 months ago - 4 years 9 months ago #184997
by h0rr0rOrg
Replied by h0rr0rOrg on topic Display responses from my survey in real time via PHP or HTML
Hi, Joffm. Thanks for the quick reply!
One of the JSon pairs in my data is "category=>poetry" where category is the Limesurvey 'code' and poetry is the Limesurvey 'answer' data.
I've gotten this far:
I can use an IF statement to pull the rows with "category=>poetry" but it shows the entire row when I echo, and if I try to use nested IF statements, the $item only returns 'poetry' and I get 'poetry' repeated over and over again.
I'm sorry. I'm learning this on the fly. My PHP knowledge is just enough to get me halfway, but not enough to get me all the way with the JSon data format.
I do greatly appreciate all the help you guys are giving me.
Angel...
One of the JSon pairs in my data is "category=>poetry" where category is the Limesurvey 'code' and poetry is the Limesurvey 'answer' data.
I've gotten this far:
Code:
$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>'; } } }
I can use an IF statement to pull the rows with "category=>poetry" but it shows the entire row when I echo, and if I try to use nested IF statements, the $item only returns 'poetry' and I get 'poetry' repeated over and over again.
I'm sorry. I'm learning this on the fly. My PHP knowledge is just enough to get me halfway, but not enough to get me all the way with the JSon data format.
I do greatly appreciate all the help you guys are giving me.
Angel...
Last edit: 4 years 9 months ago by h0rr0rOrg. Reason: updating with new info
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12790
- Thank you received: 3940
4 years 9 months ago #184998
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Display responses from my survey in real time via PHP or HTML
Hi,
use the last parameter to select the desired fields.
With this setting:
I got
Joffm
use the last parameter to select the desired fields.
With this setting:
Code:
$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'] );
I got
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- h0rr0rOrg
- Topic Author
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 0
4 years 9 months ago - 4 years 9 months ago #185064
by h0rr0rOrg
Replied by h0rr0rOrg on topic Display responses from my survey in real time via PHP or HTML
Hi, Joffm,
Thanks very much for that info. It works great for the data that is auto-generated by Limesurvey, but any data that my users input isn't showing up.
I can see id, submitdate, and lastpage, for example. But my 'author' and 'title' data is just blank. It makes the table cell for it, but there's nothing in it.
I've double-checked the spelling and capitalization on the codes, and they're correct. All lower case. Here's what I input:
And here's the echo line:
The first three show up. The last four are blank, though the table cell is created.
I tried reordering them, and I tried showing only 'title', in case it was a question of order, but that didn't work either.
Any idea why that might be?
Thanks a ton for taking time to help me!
Angel...
Thanks very much for that info. It works great for the data that is auto-generated by Limesurvey, but any data that my users input isn't showing up.
I can see id, submitdate, and lastpage, for example. But my 'author' and 'title' data is just blank. It makes the table cell for it, but there's nothing in it.
I've double-checked the spelling and capitalization on the codes, and they're correct. All lower case. Here's what I input:
Code:
['submitdate','lastpage','id','title','author','publisher','category']
And here's the echo line:
Code:
echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">A: ' . $item . '</td>';
The first three show up. The last four are blank, though the table cell is created.
I tried reordering them, and I tried showing only 'title', in case it was a question of order, but that didn't work either.
Any idea why that might be?
Thanks a ton for taking time to help me!
Angel...
Last edit: 4 years 9 months ago by h0rr0rOrg.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
4 years 9 months ago #185067
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Display responses from my survey in real time via PHP or HTML
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.
- h0rr0rOrg
- Topic Author
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 0
4 years 9 months ago #185143
by h0rr0rOrg
Replied by h0rr0rOrg on topic Display responses from my survey in real time via PHP or HTML
Thanks, Tony. I've attached the .lss and input the PHP code below.
I hope you can see what I'm missing!
I hope you can see what I'm missing!
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>
Attachments:
The topic has been locked.