Welcome to the LimeSurvey Community Forum

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

Saving answers of a user in own database

  • NiklasRaczek
  • NiklasRaczek's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago #195990 by NiklasRaczek
Saving answers of a user in own database was created 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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #196008 by Joffm
Replied by Joffm on topic Saving answers of a user in own database
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
The topic has been locked.
  • NiklasRaczek
  • NiklasRaczek's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago #196010 by NiklasRaczek
Replied by NiklasRaczek on topic Saving answers of a user in own database
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
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #196015 by holch
Replied by holch on topic Saving answers of a user in own database
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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #196016 by Joffm
Replied by Joffm on topic Saving answers of a user in own database
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
The topic has been locked.
  • NiklasRaczek
  • NiklasRaczek's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago #196019 by NiklasRaczek
Replied by NiklasRaczek on topic Saving answers of a user in own database
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 :)
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #196025 by holch
Replied by holch on topic Saving answers of a user in own database

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 answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
More

Lime-years ahead

Online-surveys for every purse and purpose