Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How to insert a random picture from my database then put it into the question?

  • waholulu
  • waholulu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 7 months ago #140734 by waholulu
Hi all,
Now I want to make a survey that let people evaluate the scene pictures I collected. But I don't know how to insert a random picture from my database then put it into the question :unsure: :unsure: ? I'm new to this software, should I add code at somewhere? Thanks !
Thank you very much for your support!

Best,
Chen
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #140744 by tpartner
Assuming you have image filenames something like image_1.jpg, image_2.jpg, image_3.jpg, image_4.jpg, you can use the Expression Manager rand() function to place something like this in an equation type question :

Code:
<img src="path/to/images/img_{rand(1, 4)}.jpg" />

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 7 months ago #140755 by darty
In this example, is there a way you can save the number of the image you have shown?

Eg. the question shows image_12.png and I would like to save the value 12 to relate the answer with the specific image...
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #140771 by holch
You can create the random number first in an equation question and then instead of the rand part from Tpartners example insert the responde of the equation question as the random number.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #140772 by holch
Actually, in Tpartners example you could read out the picture, because it is actually writing this code into the equation question already.

Let's say the random number is 5.

Then this would be saved into the random question:
Code:
<img src="path/to/images/img_5.jpg" />

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: tpartner
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #140773 by tpartner

You can create the random number first in an equation question and then instead of the rand part from Tpartners example insert the responde of the equation question as the random number.

Hmm...not sure that would work because Expression Manager wraps piped values in a <span> element. (don't ask me why :) )

Then this would be saved into the random question:

Yes, exactly ;)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose