0 votes
in SoSci Survey (English) by s094381 (120 points)

Hi Sosci Survey Team

I need to limit the number of participants that have consented to my study to 210. On page 1 of the survey, they answer a simple selection question (IC02) where 1 = consent and 2 = do not consent.

On page 2 of the the survey, placed this PHP code to limit the participants to 200:

$consentcases = statistic('count', 'IC02', 1);
if ($consentcases > 201) {
text('quotafull');
buttonHide();
pageStop();
}

But this does not seem to work, where am I going wrong?

by s094381 (120 points)
Hi, the variable IC02 is this a selection question specified like this:

IC02 Consent
1 = I agree to participate / Estoy de acuerdo
2 = I do not want to participate / No estoy de acuerdo
-9 = Not answered

My main concern is that if I use the code:

$consentcases = statistic('count', 'IC02', 1);
if ($consentcases > 201) {
text('quotafull');
buttonHide();
pageStop();
}

How do I know that it works?  If I try to test it by changing the number to 0 it does not display the message? Is there a way to test this code? We are paying participants, so we need to make sure we stop after 200 participants

1 Answer

0 votes
by SoSci Survey (309k points)

where am I going wrong?

You seem to use a limit of 201 instead of 210 in the code ;)

Okay, let's track down what's not working. Add a line of code to check the count.

$consentcases = statistic('count', 'IC02', 1);
debug($consentcases);

What does the debug information on that page display?

by s109993 (10.3k points)
quick question here: is there another way to check the structure of an array except of debug(). E.g. if I use a databank I cannot use the debug mode for testing, hence debug() would not work. And var_dump() is not possible, right?
by SoSci Survey (309k points)
Why would debug() not word when using a databank?

> And var_dump() is not possible, right?

That is correct, it would place its output somewhere before the page and destroy thw whole HTML structure.
by s094381 (120 points)
Thank you for spotting the 201/210 issue, I have corrected that :)

I added the debug code, and it says:
Debug information for $consentcases:
$consentcases = 0 (integer)
by SoSci Survey (309k points)
So, the next step is to take a look into the data, and see in there's (a) a variable IC02 and not IC02_01, and (b) if there are cases that have a 1 in this variable.
by s094381 (120 points)
The variable names are correct. My question is rather, how do I test this code? How do I know it is working properly? It is at the moment written as:

$consentcases = statistic('count', 'IC02', 1);
if ($consentcases > 210) {
text('quotafull');
buttonHide();
pageStop();
}
by SoSci Survey (309k points)
First, make the code show you the counts:

$consentcases = statistic('count', 'IC02', 1);
debug($consentcases);

Second, decrease the limit so that you test cases will trigger the filter:

if ($consentcases > 2) {
by s094381 (120 points)
Thanks! I added it is and the it seems to be counting the $consentcases: Debug information for $consentcases:
$consentcases = 1 (integer)

But what I don't get is the setting it to $consentcases > 2 to test it. Every time I test it in the Questionnaire Pages section (i.e. clicking on the green triangle to look at it), it will start the count from 0 since it does not record those. So do I have to activate the survey in order to test this function?
by SoSci Survey (309k points)
If you're running in debug mode, it should count debug cases. Make sure to complete (FINISHED=1) your test cases (go to the last page when IC02 is set via put()) so statistic() will count them. You may also choose to add an parameter to statistic() to also count incomplete cases.
by s094381 (120 points)
Thank you so much! It works now :)

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

...