0 votes
in SoSci Survey (English) by s057462 (330 points)

Hi there!

I am currently experiencing some issues when trying to set up a question requiring pictures tied to set questions/answers. When doing the pretest the answers are currently not being allocated to the correct picture.

I currently have the images set up in a random generator, with each picture allocated to it's designated question number in the coding field (e.g 01= pic1.PNG).

The questions/answers are in 'selection form', again each one allocated in number order from 1-36. e.g (FP01 = answers which correspond to pic1.PNG).

The questionnaire page is currently set up like this:

[randomly gen picture]

[PHP code]

// loopPage(37) provides a number between 0 and 36 (plus one at every repetition)
$i = loopPage(37);  // Here you can enter the number of images you want to show

// Show the chosen picture
$varID = 'FP01x'.sprintf('%02d', $i + 1);  // Variable IDs are FP01x01 to FP01x36
$img = value($varID, 'label');

// The HTML-Tag <img> shows one image, the filename will be shown with src 
html('
  <div style="margin: 3em; text-align: center">
    <img src="'.$img.'" alt="" />
  </div>
');

// Create the fitting question ID and show the question using question()
//question('FQ'.sprintf('%02d', $i + 1));
question(id('FQ', $i + 1));

[end of PHP code]

I believe that the error must currently be in the PHP code. Any help would be much appreciated!

Thanks in advance,
Afcrinlab

by SoSci Survey (302k points)
How mayn images do you show in your questionnaire? If all images are displayed, then this is a rotation, no randomization task. And then I'd recommend not (!) to use the random generator.
by s057462 (330 points)
36 Images, all displayed, with one being displayed per page.

1 Answer

0 votes
by SoSci Survey (302k points)

Instead of using a random generator, please follow the instructions in the manual Rotation, especially Rotating Questions Together with Additional Content.

The random generator is very useful when working with experimental groups, but much less helpful for stimulus rotation.

To answer your initial question, it would have been necessary to use 36 instead of 37. If there are further issues, the exact error message would be necessary for a qualified response. But as I regard the rotation manual more sensible, anyway, I wouldn't go deeper into this.

by s057462 (330 points)
I tried this but I am still having issues (apologies, coding goes over my head somewhat).

So, my PHP code currently reads:

---- begin PHP code---

if (!isset($blocks)) {
  $blocks = array(  // list of question IDs and images belonging to them
    array('FQ01', 'pro://1.png'),
    array('FQ02', 'pro://2.png'),
   .......... so on, until
    array('FQ36', 'pro://36.png'),
  );
 
  // shuffle list
  shuffle($blocks);
  // make lists available on all pages
  registerVariable('blocks');
}
 
// display blocks
$i = loopPage(36($blocks));
// display picture
html('<p><img src="'.$blocks[$i][1].'" alt="election poster"></p>');
// display question
question($blocks[$i][0]);

---end PHP code---

The error code currently shows:
"
There is an error in the PHP code:

Questionnaire Error: syntax error, unexpected 'shuffle' (T_STRING)
line: 42

PHP code

039   );
040  
041   
042   shuffle($blocks);
043   
044   registerVariable('blocks');
045 }

"
by SoSci Survey (302k points)
Would you mind posting the complete (!) PHP code in a new question. Please kindly use the {} button to format the code as code. Thank you.
by s057462 (330 points)
Apologies I am unsure of exactly what you mean, but here is the full PHP code in an individual message:
by s057462 (330 points)
if (!isset($blocks)) {
  $blocks = array(  // list of question IDs and images belonging to them
    array('FQ01', 'pro://1.png'),
    array('FQ02', 'pro://2.png'),
    array('FQ03', 'pro://3.png'),
    array('FQ04', 'pro://4.png'),
    array('FQ05', 'pro://5.png'),
    array('FQ06', 'pro://6.png'),
    array('FQ07', 'pro://7.png'),
    array('FQ08', 'pro://8.png'),
    array('FQ09', 'pro://9.png'),
    array('FQ10', 'pro://10.png'),
    array('FQ11', 'pro://11.png'),
    array('FQ12', 'pro://12.png'),
    array('FQ13', 'pro://13.png'),
    array('FQ14', 'pro://14.png'),
    array('FQ15', 'pro://15.png'),
    array('FQ16', 'pro://16.png'),
    array('FQ17', 'pro://17.png'),
    array('FQ18', 'pro://18.png'),
    array('FQ19', 'pro://19.png'),
    array('FQ20', 'pro://20.png'),
    array('FQ21', 'pro://21.png'),
    array('FQ22', 'pro://22.png'),
    array('FQ23', 'pro://23.png'),
    array('FQ24', 'pro://24.png'),
    array('FQ25', 'pro://25.png'),
    array('FQ26', 'pro://26.png'),
    array('FQ27', 'pro://27.png'),
    array('FQ28', 'pro://28.png'),
    array('FQ29', 'pro://29.png'),
    array('FQ30', 'pro://30.png'),
    array('FQ31', 'pro://31.png'),
    array('FQ32', 'pro://32.png'),
    array('FQ33', 'pro://33.png'),
    array('FQ34', 'pro://34.png'),
    array('FQ35', 'pro://35.png'),
    array('FQ36', 'pro://36.png')
  );
 
  // shuffle list
  shuffle($blocks);
  // make lists available on all pages
  registerVariable('blocks');
}
 
// display blocks
$i = loopPage(count($blocks));
// display picture
html('<p><img src="'.$blocks[$i][1].'" alt="election poster"></p>');
// display question
question($blocks[$i][0]);
by s057462 (330 points)
And the error code:
by s057462 (330 points)
There is an error in the PHP code:
Questionnaire Error: syntax error, unexpected 'shuffle' (T_STRING)
line: 42
PHP code
039   );
040  
041   
042   shuffle($blocks);
043   
044   registerVariable('blocks');
045 }
by SoSci Survey (302k points)
When I copy your code, it runs fine. Could it be that you have somehow inserted some invisible character that causes trouble? Please try to remove your PHP code element, insert a blank new one, and copy/paste your own code from above. Does the error still occur?

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

...