A Database for Contents can be found in the Special Features. This is an internal project miniature database (non-relational), stored in the data for use in the questionnaire, or can even be changed during the questionnaire. This leads to a number of different possibilities, e.g.
preset()
)In addition to this, the question types Extended Selection and Suggesting Text Input offer the possibility to access the database. This enables the programming of very extensive and/or dynamic selection questions.
The commands dbGet()
and dbSet()
are used to access the database through PHP code. The data is read to a key with dbGet()
and data can be written to the database with dbSet()
. Available keys can be listed with the command dbKeys()
.
Note: Please note: when the project is exported, the data in the Database for Contents will not be exported yet. When a project is archived, the data will be deleted rather than archived. Changing this is planned in the next version of the programme.
In the Database for Contents, pairs made up of one key each (an ID) and data can be stored.
'1'
). Control characters (e.g.) line breaks are not possible in the text – of course, HTML tags are. The data stored can be called up in the questionnaire by using the key. As depicted below, a database could contain the following pairs of keys and data:
Key | Data (Combinations) |
---|---|
A1 | (apple tree, apples) |
A2 | (pear tree, pears) |
A3 | (clementine tree, clementines) |
B1 | (6) |
B2 | (12) |
B3 | (18) |
B4 | (24) |
B5 | (30) |
First of all, the data has to be stored in a table, e.g. in excel or Open Office Calc:
In order to generate the database entries described above, your table would look as follows:
A1 | apple tree | apples |
A2 | pear tree | pears |
A3 | clementine tree | clementines |
B1 | 6 | |
B2 | 12 | |
B3 | 18 | |
B4 | 24 | |
B5 | 30 |
Save this table in a CSV (Character Separated Values) format. This is nothing more than a text file in which the values are listed in a row and are separated by a given character (e.g. tab).
Now select the CSV file in Special Features → Database for Contents → Import Data (CSV) and confirm with OK. In the following window, a few more details will be queried – normally, SoSci Survey recognises the correct format settings for the file automatically.
If you are working in a multilingual project, you can store different data for different language versions. The programme always checks, whether a separate entry exists for the current language version – and when not, uses the entry from the base language (Multilingual Surveys).
Note: Every line in the table must have at least 2 columns. Lines that only contain one key, or no data at all, are ignored during the import.
If you want to change the data, import a new/another CSV file. Duplicated keys are updated (overwritten) correspondingly. Apart from this, existing keys are not changed.
In order to delete entires, you can either remove individual entires or delete the entire database (all entries) in the “Delete Entries” tab.
Using the function dbSet()
, entries in the Database for Contents can also be changed or deleted during the questionnaire.
You may update the “Database for Contents” during data collection, using dbSet()
. If necessary, you can download the database contents as CSV file at any time:
Special Features → Database for Contents → Button “Download”
In a study, 500 newspaper articles written by different people should be assessed. The articles come from an electronic database and are already available in tabular form. In order to ensure that each article is assessed equally often, randomization using urns is used. However, it would be extremely inefficient to create 500 individual text elements.
First of all, the articles must be imported into the internal project database. In order to do this, a table with the 500 articles is created in a spreadsheet as follows:
Key | Title | Text |
---|---|---|
a1 | Train Drivers' Strike: Society at Hostage | The freedom to strike is in the constitution for good reason … |
a2 | The Role of Juncker's Network | President of the EU Commission, Juncker, maintains relations with the main leaders of Europe … |
a3 | Carsten Maschmeyer Sues Swiss Bank | According to information from the Suddeutsche, the investor Carsten Maschmeyer has … |
The table is saved as a CSV file. The first row here is only used for labeling – the CSV should not include this. The CSV file is imported into the project in Special Features → Database for Contents.
The numbers 1 to 500 (one number per line) are in the “article” urn. Please see Randomization Using Urns for details regarding urn draws.
In the questionnaire, a ballot is drawn from the urn and the entry read out of the database using dbGet()
. Afterwards, the article is shown via html()
:
urnDraw('article', 'IV01'); $key = 'a'.value('IV01_01'); // write an "a" before the number $content = dbGet($key); html(' <h2>'.$content[0].'</h2> <div>'.$content[1].'</div> ');
It was asked in the pre-survey of a diary study which television station a person uses. In further enquiries during the diary study, the daily period of use for the respective station was prompted. For this purpose, only the stations that were selected in the pre-survey should be offered in a text input.
SoSci Survey's mailings function is used for the entire diary study. By using caseSerial()
, a unique personal code can be generated in every questionnaire.
Note: If the e-mail address is only collected in the first questionnaire (Multi-Wave Surveys with Self-Recruited Respondents), please use value()
with the identifier of the opt-in question instead of caseSerial()
in this questionnaire.
In the pre-survey, the television channels used are prompted in the multiple-choice “FS01” on page 2 of the questionnaire. The selection is noted in the database on page 3 (or later):
$station = getItems('FS01', 'is', 2); $key = 'FS-'.caseSerial(); // the mailings number is preceded with a "FS-", so that other content can still be saved in the database. dbSet($key, $station);
In the daily questionnaires, the period of use for the station is prompted using the text input “NU03”. This question contains the same items in the same order as the multiple selection “FS01”. The following PHP code reads the data from the database and only shows the corresponding input fields:
$key = 'FS-'.caseSerial(); $station = dbGet($key); question('NU03', $station);
Important: dbGet()
always returns an array – even if you only store a single value with dbSet()
.
If you store a single value in the first questionnaire, you must access the first (and only) array element in the other questionnaire using square brackets ([0]
).
$group = value('RG01'); $key = 'RG-'.caseSerial(); // Again, a prefix is used for the database entry to keep all options open dbSet($key, $group);
$key = 'RG-'.caseSerial(); $data = dbGet($key); if ($data) { $group = $data[0]; // cache the value into an internal variable, // to use the value later via value() (optional) put('IV01_01', $group); } else { // show error message that something went wrong show('XY01'); put('IV01_01', -1); }
The PHP code for the second questionnaire also provides for the case that no matching entry is found in the content database.
In a survey, participants have to fill in several lengthy scales. As a thank-you, they can look at an analysis of their results two weeks later. The analysis cannot be conducted live (valueMean()
, Count Points for Answers) because the standard values from the sample have to be determined first of all. To call up their results, the participants have to note down a code because the survey is conducted anonymously.
Therefore, an 8-digit random code is created in the first questionnaire, saved in the database and displayed:
$chars = 'ABCDEFHKLMNPRSTUVWXYZ23456789'; // characters that normally cannot be confused $code = ''; for ($i=0; $i<8; $i++) { $code.= $chars[mt_rand(0, strlen($chars)-1)]; } // save code in database (preceded with "X-") put('IV02_01', 'X-'.$code); // display code html('<h1>Results</h1><p>Please note down <strong>'.$code.'</strong></p>');
The data is analysed after collection and three result values are calculated for each participant. These are – together with the code from IV02_01 – saved in a table as a CSV file:
X-ABCDEF12 | 7 | 19 | 8 |
X-CDEFG234 | 24 | 16 | 19 |
X-ZU7652AB | 15 | 95 | 80 |
In the second questionnaire, the participants have to enter their code first of all (text input “AB01_01”). Then, on the second page, a check is performed as to whether it exists in the database and, when yes, the results are then displayed.
$key = 'X-'.value('AB01_01'); // preceded with X here again $result = dbGet($key); // when code is wrong, show code request (previous page) again if ($result === false) { text('wrong code'); repeatPage(); } // otherwise, result is shown html(' <p>Well-restedness: '.$result[0].'%</p> <p>Astuteness: '.$result[1].'%</p> <p>Friendliness: '.$result[2].'%</p> ');
In a (non-anonymous) customer survey, some master data is already known – however, it should be updated/completed in the questionnaire. The customers receive personalized links (access “Access Codes”) with a code assigned to each customer beforehand. 12-digit numbers are used for these so that codes belonging to other customers cannot be guessed and their data accessed, which could easily be done if a consecutive customer number was used.
A table is created with the code in the first column and the master data next to it. The table is saved as a CSV file and imported into the internal project database.
12345678ABCD | SoSci Survey GmbH | Marianne-Brandt-Str. | 29 | 80807 | Munich |
9876542UBGAD | Company | Road | 7 | 12345 | Town |
72KU635485UG | MSD-Media GbR | Korbinianstr. | 17 |
The code is transferred as the access code (s
) in the personalised URL to the Questionnaire and is therefore available in PHP code via caseSerial()
.
The text input “ST01” has the following input fields: company (01), street (02), house number (03), ZIP code (04), place (05). By using prepare()
, the known data is now entered – if necessary, the customer can adjust this when filling it in.
$key = caseSerial(); $info = dbGet($key); if ($info !== false) { preset('ST01_01', $info[0]); preset('ST01_02', $info[1]); preset('ST01_03', $info[2]); preset('ST01_04', $info[3]); preset('ST01_05', $info[4]); } // now show the question question('ST01');
To add an entry to the database for content during the interview, it must be read out, added and then written again.
For example, under the key “FS-<Serial number>” a-priori data was stored (3 entries per person, i.e. indices 0 to 2). In survey wave 1 a product preference from question PP01 is now to be added as fourth date (index 3). The following PHP code could then be placed on the page after the page with PP01 (see notes on value()
)
$key = 'FS-'.caseSerial(); // Reading data $data = dbGet($key); if ($data === false) { // No data found - maybe show warning $data = array(-8, -8, -8); // ... and initialize the data element } // Add the answer from PP01 $data[3] = value('PP01'); // save entry again $data = dbSet($key, $data);
The content database can also be used to gradually narrow down long selection lists. In the following example, a district is to be selected first and then, in the next step, a station within the district.
For this purpose, a list is first created in the content database, which contains the city districts and the stations. It is important to assign suitable database keys. These must meet the following criteria:
The list for the import could look like the following:
S01 1 District A S02 2 District B S03 3 District C ... S50 50 District Zeta H0101 101 station "Ammersberg" in district A H0102 102 station "Breitenbach" in district A H0103 103 station "Clemensstraße" in district A ... H5017 5015 station "Zwiebelturm" in district Zeta
Now two questions of type Extended Selection are created in the question catalog. The options are to get these two questions from the database. For the prefix in the question for the districts set “S” and for the database prefix for the stop question set “H”. The preview shows now all stations.
Tip: Instead of an extended selection, you can also use a Suggesting Text Input. This is useful if, for example, you have a lot of answer options for the districts.
If the preview of the questions corresponds to your desires (only with the stops still too many indicated), then it goes now and Compose Questionnaire. There you place the questions for the city districts (“AF01” in the example) on one page. On the next page, a little PHP code and the function question()
is used to place the question for the stops (“AF02”). The parameter 'filter'
is used here to ensure that only the matching stops are displayed.
// First read out the selected district $district = value('AF01'); // Then create the prefix for the matching stops $prefix = 'H'.sprintf('%02d', $district); // Then show the question about the district with the appropriate options. question('AF02', 'filter='.$prefix);
The function sprintf()
ensures that the response code from AF01 is output with two digits (format code %02d
). 1
thus becomes the string '01'
.
The dot (.
) is used in PHP to concatenate strings. So if in the variable $prefix
e.g. “H01” is stored, then 'filter='.$prefix
becomes 'filter=H01'
.