Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: Reading from a Database

Reading from a Database 1 Jahr 2 Monate her #97389

  • FewPexia
  • FewPexias Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
Just discovered LimeSurvey and it looks very useful!
We have been working on a long time enterprise application that includes some surveys and related items along with many other functions.
We want to be able to develope new surveys and deploy them easily. LimeSurvey seems to be close to what we need.
Wondering about Oracle as the database but that is a secondary issue since we can manage that using the mysql database on the backend if needed. Any information on this would also be useful, though.

We need to be able to look-up information in our database based on user entered information and then display this back in the survey.
Some examples:
- if the user enters a dealer code, we want to be able to look up the dealer name, address, etc. from a database and then include this in that user's survey.
- if the user enters a VIN we want to look up the Division, Model, and Model Year, etc. from a database and then include this in that user's survey.
Also some of this looked up information may drive further question directions. And some information may need to be read only and some editable while some may be hidden.

We are working with large data so having users place all values in the survey itself is not feasible.
I bet this have been done before. Any info on this would be great.

Thanks in advance.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97412

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 349
You can make an AJAX call to remote scripts that access your external database(s). The details of the PHP are out of the scope of this forum but if you search the forum for "AJAX", you should find examples of how to handle the returned data (load questions).
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97432

  • FewPexia
  • FewPexias Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
Thanks for the advise.
I started experimenting.
I have Javascript calling a php script that just returns text.
I should have no problem making the php scripts I need to access the database and return values.
I am having problems figuring out all the question (and answer) attributes or properties.
Are these documented some where?

Here is my php file:
<?php
echo "HelloWorld!";
?>

Here is the JavaScript I am using for a question which calls this php file.
<p> Test Text</p>
<p>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$.get("upload/templates/helloWorld.php", function(data) {
alert("data loaded: " + data);
$('body').append(data);
$('#answer{SGQ}').val('ABC ' + data);
$('#question{QID}').text("XYZ " + data); // works but then other stuff does not work.
});
});
</script></p>

The code gets executed when the page is loaded.
There is some HTML to write out some text "Test Text" as the question.
Then the php script is called to get "HelloWorld".
The alert work fine.
Writing to the body of the page works find.

I can write thr answer as above if I comment out writing to the question.
Or
I can write the question text above and then the answer seems to be gone.

Are there some attributes/properties that need to be set to write and keep both the question and answer?
Where are things like .append, .val, .text documented?
What other attributes/properties/methods are there for questions or answers?

Thanks for any help or pointers.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97433

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 349
Assuming the question that you are trying to load is a short-text and your code is in the source of that question, try:
$('#question{QID} input[type="text"]').val('XYZ ' + data);
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97434

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 349
Where are things like .append, .val, .text documented?
jQuery - jquery.com/
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97435

  • FewPexia
  • FewPexias Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
Thanks for the help but this does not do what I want.
this:
$('#question{QID} input[type="text"]').val('XYZ ' + data);
writes to the answer. (I am trying to write the question.)
This also writes to the answer:
$('#answer{SGQ}').val('ABC ' + data);
I am trying to write the question.
This writes the question but then the answer is no longer displayed (or visible).
$('#question{QID}').text("123 " + data);
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97436

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 349
Ah, sorry, I assumed you were trying to load a question answer.

The selector required to pipe in the question text would depend on the template used.

What template are you using?

Can you activate a test survey for us to see the source code?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97437

  • FewPexia
  • FewPexias Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
I am using the default template -
I am very new to this
This is all local so I cannot activate anything but if you explain how I can export the survey I can do that if that would help.
In a nut shell, I am trying to learn what it would take to read and write between survey pages and a database.
Since I am referencing the question, I assumed there would be an easy way to write to the question text as well as the answer to the question.
Like I explained above, I seem to be able to write to the question text but then the answer is no longer shown on the page. I guess I am writing to the question text incorrectly.
The question is Short free text and not Mandatory.
Thanks again!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97438

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 349
I seem to be able to write to the question text but then the answer is no longer shown
You're not writing to the question text, you're writing to the while question :laugh:

To write to the question text in the default template, try this:
$('#question{QID} td.questiontext').text('XYZ ' + data);
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reading from a Database 1 Jahr 2 Monate her #97439

  • FewPexia
  • FewPexias Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
Thanks much! That did the trick.
Now I see, by looking at the resulting source for the page where the question26 and the questiontext classes are and I am starting to get the hang of it.

I will try and post a simple way of reading from the database and writing questions and answers from the results in the next couple of days. Perhaps it will help someone else out.

Thanks for the quick help.

Also the pointer to jQuery which I will look more into also.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.152 Sekunden
Donation Image