0

I have the following HTML code:

<tr>
  <td class="tablecontent" style="background-color: <?= $DATA_COLOR ?>;">
    <?= $oLanguage->getExpression('optherapy', 'revisionIndikation', 'Indication') ?>
  </td>
  <td class="tablecontent" style="background-color: <?= $DATA_COLOR ?>;">
    <select id="op5revindselect" name="cbOP5RevisionIndikation[]" multiple="multiple" data-placeholder="Mehrfachauswahl durch Ctrl/Strg + LMausClick ...">
      <!-- <option><?= $oLanguage->getExpression('optherapy', 'revisionIndikationChoice', 'revision surgery - please choose') ?></option> !-->
      <option value="1" <?=$ optherapie->getOP5RevisionIndikation() == '1' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation1', 'Inner Hernia (Meso)') ?>
      </option>
      <option value="2" <?=$ optherapie->getOP5RevisionIndikation() == '2' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation2', 'Inner Hernia (PETERSON)') ?>
      </option>
      <option value="3" <?=$ optherapie->getOP5RevisionIndikation() == '3' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation3', 'Weight Regain') ?>
      </option>
      <option value="4" <?=$ optherapie->getOP5RevisionIndikation() == '4' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation4', 'Weight Loss Failure') ?>
      </option>
      <option value="5" <?=$ optherapie->getOP5RevisionIndikation() == '5' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation5', 'Stenosis of Anastomosis') ?>
      </option>
      <option value="6" <?=$ optherapie->getOP5RevisionIndikation() == '6' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation6', 'Dysphagia') ?>
      </option>
      <option value="7" <?=$ optherapie->getOP5RevisionIndikation() == '7' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation7', 'Reflux') ?>
      </option>
      <option value="8" <?=$ optherapie->getOP5RevisionIndikation() == '8' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation8', 'Biliary Reflux') ?>
      </option>
      <option value="9" <?=$ optherapie->getOP5RevisionIndikation() == '9' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation9', 'Malnutrition') ?>
      </option>
      <option value="10" <?=$ optherapie->getOP5RevisionIndikation() == '10' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation10', 'Diarrhea') ?>
      </option>
      <option value="11" <?=$ optherapie->getOP5RevisionIndikation() == '11' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation11', 'Gastrogastric Fistula') ?>
      </option>
      <option value="12" <?=$ optherapie->getOP5RevisionIndikation() == '12' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation12', 'Perforation of an Ulcus') ?>
      </option>
      <option value="13" <?=$ optherapie->getOP5RevisionIndikation() == '13' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation13', 'Chronified Ulcus') ?>
      </option>
      <option value="14" <?=$ optherapie->getOP5RevisionIndikation() == '14' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation14', 'Chronified Pain') ?>
      </option>
      <option value="15" <?=$ optherapie->getOP5RevisionIndikation() == '15' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation15', 'Ileus') ?>
      </option>
      <option value="16" <?=$ optherapie->getOP5RevisionIndikation() == '16' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation16', 'Choledocholithiasis after Gastric Bypass ') ?>
      </option>
      <option value="17" <?=$ optherapie->getOP5RevisionIndikation() == '17' ? 'selected' : '' ?>>
        <?= $oLanguage->getExpression('optherapy', 'revisionIndikation17', 'Leakage') ?>
      </option>
    </select>
  </td>
</tr>

This is the HTML part within a class-based PHP code.

Now I want to redisplay the chosen results from the database by reading the table field's content. The content is saved in a comma-separated fashion, e. g. "3, 7, 9, 16" (cf. MySQL query: How to properly identify and retranslate comma-separated result values to the original notions using CONCAT_WS and COALESCE).

The PHP class-based reading method has been defined as ...

public function read() {

global $UNDEFINEDDATE, $oDatabase, $oLanguage;

$rev = $this->getLastCRFRevisionNr();

$qBaseline = ' SELECT ' .
             ' timestamp, ' . 
             blah blah blah,
             ' OP2RevisionIndikation, ' .
             blah blah blah
             ' FROM dat_optherapie ' .
             " WHERE patID = $this->iPatientID " .
             " and revision = $rev; ";

Now, the code for reading these data is as follows:

$haveOP1RevisionIndikation = explode(', ', $aBaselineData['OP1RevisionIndikation']);
$this->setOP1RevisionIndikation($haveOP2RevisionIndikation);

This, however, is not sufficient to display the entered values in HTML when calling the page again.

I think that these last 2 lines are essential for that.

Has anyone an indication how to solve that?

yivi
  • 42,438
  • 18
  • 116
  • 138
mtjmohr
  • 99
  • 9
  • 3
    'Works'? Perhaps we have different definitions of 'works'. My suggestion would be either normalise your schema or don't bother with a relational database – Strawberry May 05 '18 at 07:40
  • first thought: do you have `error_reporting` && `display_errors` turned on? second thought: the "essential" lines seem weird, maybe when you `setOP1RevisionIndikation` the variable should be `haveOP*1*RevisionIndikation`? – Jakumi May 05 '18 at 07:57
  • @Jakumi: Thank you for your comment, I will see into the error output. – mtjmohr May 05 '18 at 09:28

1 Answers1

1

Since your getter-method will return array('3', '7', '9', '16') [verify this with a var_dump()], your condition

$optherapie->getOP5RevisionIndikation() == '3'

will always return false (because array('3', '7', '9', '16') != '3').

What you want to do is an in_array-check, not an equals-check:

<option value="3" <?= in_array('3', $optherapie->getOP5RevisionIndikation()) ? 'selected' : '' ?>>
Peter van der Wal
  • 11,141
  • 2
  • 21
  • 29