Saving answers of a user in own database

More
1 month 3 weeks ago #195990 by NiklasRaczek
Hey guys,

I have 5 surveys with a lot of questions. Everey survey is only for invited people reachable.
After a User answered a survey, I want to save those answers automatically in a datbase lying on my server (same server where LS is located).

I was thinking about an AJAX part in last question, so that I can iterate through all questions and save the results of the user directly in my database (with php maybe).

Another way would be using End-URL and Limesurvey RemoteControl (I found out that there is a api remotecontrol where i can use some functions like "list_questions" and maybe I can get results out of that).

Do you think that one of those ways are possible or if both could work, wiche one is better practice ?
How would you do this ?

Best regards, Nick

LimeSurvey
Version 3.21.2

Please Log in to join the conversation.

LimeSurvey Partners
More
1 month 3 weeks ago #196008 by Joffm
Hi,
both is doable.
But consider: If you do an ajax call on the last page the respondent still may leave the survey (though this is not very probable). So you cannot distinguish between completes and incompletes.

And the other thing by an end-url?
I'd prefer that. And because I am not very familiar with the API, I usually use php with direct calls to the database(s).
We did this recently analysing a psychological test and creating some charts, reports, and so on.
In my opinion this way you are most flexible.
You see LS stores the results of multiple questions as "Y" or blank, of gender questions as "M", "F". Maybe you want to recode this before storing in your database.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 month 3 weeks ago #196010 by NiklasRaczek
Hi Joffm,
first of all thank you for your respond.

Yes you're right the first solution is tricky cause the AJAX should start after clicking "submit" and after checking all questions (if they were answered).

So the second solution sounds better.
So you mean that you have an php file wiche connects to your database(s) directly after the user is entering the end_url correct ?
And how do you get the information out of the survey in your php file ? So for that I thought the LS RemoteControl is necessary to get the answers of a Survey.

Nick

Please Log in to join the conversation.

More
1 month 3 weeks ago #196015 by holch
The LS Remote Control is necessary if you do not have direct access to the database of LS. If you have direct access to the database, which you seem to do because you host it yourself, than you can just use normal SQL queries via any programming language (e.g. PHP or Python, etc.) to read data from the database.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
1 month 3 weeks ago #196016 by Joffm
No, I do not have a general php file.
But that's not a difficult thing.

You have the credentials of the LS database and of your database. You said both are installed on your server.
So connect to them by any MySQL library (mysqli, PDO, MeekroDB,...)
and do a "SELECT * from "lime_survey_[SurveyID] WHERE SID=[SAVEDID]"

Because the column names of LimeSurvey are the SGQA-Codes, you may map them to the column names in your database.

And insert into yours.

But anyway you should try the API.
There are a few examples here.

after the user is entering the end_url correct ?

The user does not enter the end-url. You enter the end-url to your php file with the EM parameter of the {SAVEDID} added

Best before: Have a look at the lime_survey_[SurveyID] table with phpMyAdmin or something else.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 month 3 weeks ago #196019 by NiklasRaczek
To be honest I didn't know that there is a database of LS itself.
Daam that makes it way easier.
Thank you for your help joffm and holch :)

Please Log in to join the conversation.

More
1 month 3 weeks ago #196025 by holch

To be honest I didn't know that there is a database of LS itself.

Where did you think all the information was stored?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More

Start now!

Just create your account and start using Limesurvey today.

Register now