Welcome to the LimeSurvey Community Forum

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

Long if-if-if to emulate array does not work

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
3 years 1 month ago #213744 by Jmantysalo
I have a slightly complicated situation. An URL for survey contains for example puolue=5. Then by using panel integration I connect GET-parameter puolue to a (hidden) question with code puolueid. Then I have a text display with value

{if (puolueid=='1', 'Keskusta', if (puolueid=='2', 'Kokoomus', if (puolueid=='3', 'Kristillisdemokraatit', if (puolueid=='4', 'Perussuomalaiset', if (puolueid=='5', 'RKP', if (puolueid=='6', 'SDP', if (puolueid=='7', 'Vasemmistoliitto', if (puolueid=='8', 'Vihreä Liitto', if (puolueid=='9', 'Avoin puolue', if (puolueid=='10', 'Eläinoikeuspuolue', if (puolueid=='11', 'Feministinen puolue', if (puolueid=='12', 'Kansalaispuolue', if (puolueid=='13', 'Liberaalipuolue', if (puolueid=='14', 'Liike nyt', if (puolueid=='15', 'Piraattipuolue', if (puolueid=='16', 'Seitsemän tähden liike', if (puolueid=='17', 'Sininen tulevaisuus', if (puolueid=='18', 'Suomen kommunistinen puolue', if (puolueid=='19', 'Suomen Kansa Ensin', if (puolueid=='20', 'Tasapainon puolesta - IPU', 'VIRHE'))))))))))))))))))))}

Now that works, "RKP" is show to the user. It works up to puolue=9, but with puolue=10 I get

500: Internal Server
ErrorCDbCommand ei voinut suorittaa SQL-komentoa: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column '331752X3X12' at row 1

A  bug? Something I do not understand? Some way to make this with less code?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #213760 by Joffm
Less code?
Use a question of type long text ("names") where you enter the names in the default answer.
Each region in one line, right padded that all have the same length, lets say 30 characters.
then you can calculate the start by the GET parameter 
(Param-1)*32
and capture the name by something like 
{trim(substr(names,(Param-1)*32,30)}

This is only the rough idea.
You have to consider two additional characters (LF and CR), therefore "32".

Later I'll send a sample survey.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Jmantysalo
The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
3 years 1 month ago #213761 by Jmantysalo
Replied by Jmantysalo on topic Long if-if-if to emulate array does not work
Great idea! I'll implement that, and no need for example survey.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #213762 by DenisChenu
Replied by DenisChenu on topic Long if-if-if to emulate array does not work
Because puolueid can not 1 and 2 and other at same time : easiest way
{if (puolueid=='1', 'Keskusta')}
{if (puolueid=='2', 'Kokoomus')}
{if (puolueid=='3', 'Kristillisdemokraatit')}
{if (puolueid=='4', 'Perussuomalaiset')}



> ErrorCDbCommand ei voinut suorittaa SQL-komentoa: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column '331752X3X12' at row

I think it was fixed in 4.X too ?
github.com/LimeSurvey/LimeSurvey/blob/50...lease_notes.txt#L157

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: tpartner
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose