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

More
4 months 1 week 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?

Note: If I asked something and forgot to say version, I am using LS 4.x.

Please Log in to join the conversation.

More
4 months 1 week 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

Please Log in to join the conversation.

More
4 months 1 week ago #213761 by Jmantysalo
Great idea! I'll implement that, and no need for example survey.

Note: If I asked something and forgot to say version, I am using LS 4.x.

Please Log in to join the conversation.

More
4 months 1 week ago #213762 by DenisChenu
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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now