0 votes
in SoSci Survey (English) by s182763 (225 points)
reopened by SoSci Survey

The following code takes answers from subject input, and creates the input as item for a slider question.

$dataMon = dbGet('mon-'.caseSerial());
$dataTue= dbGet('tue-'.caseSerial());
$dataWed = dbGet('wed-'.caseSerial());
$data = array_merge($dataMon, $dataTue, $dataWed);
foreach ($data as $key => $text) {
  if (trim($text) != '') {
    $itemID = $key + 1;
    replace('%item'.$itemID.'%', $text);
  }
}

However, empty text inputs are still counted as items even though:

 if (trim($text) != '') {...}

Is supposed to prevent that right? Here are the error codes I get:

And here is what the entries in the database look like:

To be clear: If mon-2, mon-[3], mon-[4] are empty, they shouldn't become an item in the slider.
Any ideas what is going wrong here? I appreciate the time and help!

1 Answer

+1 vote
by SoSci Survey (330k points)
selected by s182763
 
Best answer

Any ideas what is going wrong here?

Just the opposite, it looks quite good so far.

The only thing you need to change is to create a list of items that are to be shown:

...
$items = [];  // new
foreach ($data as $key => $text) {
  if (trim($text) != '') {
    $itemID = $key + 1;
    replace('%item'.$itemID.'%', $text);
    $items[] = $itemID; // new
  }
}

question('AB01', $items);  // new

Further, I assume some problems with varying lengths of what dbGet() returns. If I understand your structure correctly, you have up to 7 days x 5 texts = 35 texts. So you will need 35 items.

And you will have to make sure that the frist Friday text is always on position 21, so that the answer to the text is always in item 21. This could be accomplished by a few loops around the arrays returned by dbGet().

by s182763 (225 points)
This fixed it!

Thank you!

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

...