0 votes
in SoSci Survey (English) by s199634 (130 points)
edited by SoSci Survey

Hello everyone!

I'm currently facing some difficulties in linking a random number generator with SoSci Survey and I'm hoping for your assistance.

I have a PHP code that generates a random number and, based on this number, displays a single image. Now, I want to link this random number with one specific items in SoSci Survey so that depending on which image is displayed, the corresponding item appears on the next page of the survey. I basically have three items PD_RD (PD01), PD_FM (PD02), PD_KLI (PD03) corresponding to the images.

Here's my current code for the ramdomizer:

$number = value('RD02'); // Read out the random number drawn
 
// Display graphic depending on the number
// (HTML code is used for this)
if ($number == 1) {
  html('<p><img src="RD.JPEG"></p>');
} elseif ($number == 2) {
  html('<p><img src="FM.JPEG"></p>');
} elseif ($number == 3) {
  html('<p><img src="KLI.JPEG"></p>');

The problem is that the item is only displayed on a later page, so I probably need to use the random generator again on the new page? However, I'm not sure how to best implement this.

I would greatly appreciate it if someone could help me solve this issue. Thank you very much in advance for your assistance!

1 Answer

0 votes
by SoSci Survey (328k points)

so I probably need to use the random generator again on the new page?

The random generator will store the value in the dataset, so value() will work find without repeating the random generator. Just replace the html() in your code by question().

$number = value('RD02'); // Read out the random number drawn
 
if ($number == 1) {
  question('PD01');
} elseif ($number == 2) {
  question('PD02');
} elseif ($number == 3) {
  question('PD03');
}
by s199634 (130 points)
Thank you! I tried out the code, but unfortunatly it just appears on the bottom of the page as you can see below:

"$number = value('RD02'); // Read out the random number drawn if ($number == 1) { question('PD01'); } elseif ($number == 2) { question('PD02'); } elseif ($number == 3) { question('PD03'); }"

I already tried it out by replacing the name of the item PD_RD (PD01), PD_FM (PD02), PD_KLI (PD03) but this did not change anything.
by SoSci Survey (328k points)
> I tried out the code, but unfortunatly it just appears on the bottom of the page as you can see below:

Please use a "PHP code" element instead of an "HTML code" element.
https://www.soscisurvey.de/help/doku.php/de:create:php

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...