Welcome, Guest
Username: Password: Remember me

TOPIC: Connect LimeSurvey with database (or any other form of text storage)

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 2 months ago #73930

I am trying to make a very simple example, according to your instructions and with the help of the example you pinpointed. So:

I created a php file (helloWolrd.php) and placed it in upload/templates/:

<?php
echo "HelloWorld!";
?>

Then I placed some javascript code in the source of the question, which just calls the php file and requests data:

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$.getJSON('templates/helloWorld.php', function(data) {
alert(data);
});
});
</script>

So I expected to see an alert window showing "Hello World!", but nothing happens... Am I missing something?!
The administrator has disabled public write access.

Re: Connect LimeSurvey with database (or any other form of text storage) 2 years 2 months ago #74008

  • Something
  • Something's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 1
yannischris wrote:
I checked out this example but I don't think that the script makes a connection with a database. IT reads files from a csv file, which is a different case. So the question remains:
Is there a a way to query a database in order to pre-fill the answer of a question in a limesurvey questionnaire?"
yannischris wrote:
So if I place a php script there, the javascript automatically locates the script (given that I have provided the right name)?
And if this php script fetches data from a db, can it pass those data to the javascript, which in turns can use them to e.g. prefill answers to the questionnaire?
I found a good example / tutorial that I followed and worked flawlessly. I am not sure if I am allowed to post external links here, but you can find it in google search using the keywords "how to retrieve data from mysql using javascript". It's the 2nd result.

It describes how to use javascript with ajax in order to a) make a customizable mysql query from within a webpage, and b) to display the resulting data on the same page. The connection to the database is done by means of a php file.

In my local installation of Limesurvey (using xampp) I placed the php file in the htdocs/limesurvey directory (where also other limesurvey php files are located) and it worked fine.

Hope you find this info helpful!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.096 seconds
Donation Image