php和mysql:使用内爆保存多个值,使用explode读取并返回它们?

mv1qrgav  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(189)

我的文件optherapie.php包含以下php和html代码:

<?php
[...]
if ($_POST['cbOP2Revision'] == '2') {
  $optherapie->setOP2Revision($_POST['cbOP2Revision']);
  $OP2RevisionIndikation = implode(', ', $_POST['cbOP2RevisionIndikation']);
  $optherapie->setOP2RevisionIndikation($OP2RevisionIndikation);
  $OP2RevisionArt = implode(', ', $_POST['cbOP2RevisionArt']);
  $optherapie->setOP2RevisionArt($OP2RevisionArt);
  //$optherapie->setOP2RevisionIndikation($_POST['cbOP2RevisionIndikation']);
  //$optherapie->setOP2RevisionArt($_POST['cbOP2RevisionArt']);
}
[...]
?>

[...]

<div id="OP2_RevisionIndikationArt" style="display:none">

<table width="95%" align="center" border="<?= $BORDER_TABLE ?>" cellpadding="0" cellspacing="0" frame="" style="margin-left: 40px;" >
<colgroup>
<col style="width: 185px" />
<col />
</colgroup>

<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="op2revindselect" name="cbOP2RevisionIndikation[]" multiple="multiple" data-placeholder="Mehrfachauswahl durch Ctrl/Strg + LMausClick ...">
    <!-- <option><?= $oLanguage->getExpression('optherapy', 'revisionIndikationChoice', 'revision surgery - please choose') ?></option> !-->
    <option value="1" <?= $optherapie->getOP2RevisionIndikation() == '1' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionIndikation1', 'Inner Hernia (Meso)') ?></option>
    <option value="2" <?= $optherapie->getOP2RevisionIndikation() == '2' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionIndikation2', 'Inner Hernia (PETERSON)') ?></option>
    <option value="3" <?= $optherapie->getOP2RevisionIndikation() == '3' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionIndikation3', 'Weight Regain') ?></option>
    <option value="4" <?= $optherapie->getOP2RevisionIndikation() == '4' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionIndikation4', 'Weight Loss Failure') ?></option>
    [...]
    <option value="17" <?= $optherapie->getOP2RevisionIndikation() == '17' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionIndikation17', 'Leakage') ?></option>
    </select>
  </td>
</tr>
<tr>
  <td class="tablecontent" style="background-color: <?= $DATA_COLOR ?>;" >
    <?= $oLanguage->getExpression('optherapy', 'revisionArt', 'Type') ?>
  </td>
  <td class="tablecontent" style="background-color: <?= $DATA_COLOR ?>;">
    <select id="op2revartselect" name="cbOP2RevisionArt[]" multiple="multiple" data-placeholder="Mehrfachauswahl durch Ctrl/Strg + LMausClick ...">
    <!-- <option><?= $oLanguage->getExpression('optherapy', 'revisionArtChoice', 'revision surgery - please choose') ?></option> !-->
    <option value="1" <?= $optherapie->getOP2RevisionArt() == '1' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionArt1', 'Devolvement laparoscopically') ?></option>
    <option value="2" <?= $optherapie->getOP2RevisionArt() == '2' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionArt2', 'Devolvement openly') ?></option>
    <option value="3" <?= $optherapie->getOP2RevisionArt() == '3' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionArt3', 'Dilatation') ?></option>
    <option value="4" <?= $optherapie->getOP2RevisionArt() == '4' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionArt4', 'Band Explantation') ?></option>
    [...]
    <option value="20" <?= $optherapie->getOP2RevisionArt() == '20' ? 'selected' : '' ?>><?= $oLanguage->getExpression('optherapy', 'revisionArt20', 'Stent Implantation') ?></option>
    </select>
  </td>
</tr>

</table>

</div>

这个代码做它应该做的:选择e。g。前两个选项分别作为“1,2”写入数据库。
在php5\u classoptherapie.php中,用于读取数据库值的对象类如下所示:

[...]
$qBaseline = 'SELECT ' .
             ' timestamp, ' .
             ' Datum, ' .
             ' DurchfuehrungVerantwortung, ' .
             ' OPTherapie, ' .
             [...]
             ' OP2RevisionIndikation, ' .
             ' OP2RevisionArt, ' .
             [...]
             ' FROM dat_optherapie ' .
             " WHERE patID = $this->iPatientID " .
             " AND revision = $rev; ";

$rResult = $oDatabase->query($qBaseline);

if ($oDatabase->getNumRows($rResult) == 0) {
  echo '<p class="error">Es sind keine noch Daten vorhanden!</p><br />';
} else {
  $aBaselineData = $oDatabase->getArrayAssoc($rResult);
[...]
//$haveOP2RevisionIndikation = explode(', ', $aBaselineData['OP2RevisionIndikation']);
//$this->setOP2RevisionIndikation($haveOP2RevisionIndikation);
//$haveOP2RevisionArt = explode(', ', $aBaselineData['OP2RevisionArt']);
//$this->setOP2RevisionArt($haveOP2RevisionArt);
$this->setOP2RevisionIndikation($aBaselineData['OP2RevisionIndikation']));
$this->setOP2RevisionArt($aBaselineData['OP2RevisionArt']);

在php5\u classoptherapie.php中,用于保存数据库值的对象类如下所示:

[...]
$OP2RevisionIndikation = $this->getOP2RevisionIndikation();
$OP2RevisionArt = $this->getOP2RevisionArt();
[...]
$qInsertBase = 'INSERT INTO dat_optherapie (' .
               ' patID, ' .
               ' sessionID, ' .
               ' timestamp, ' .
               ' userID, ' .
               ' Datum, ' .
               ' DurchfuehrungVerantwortung, ' .
               ' revision, ' .
               ' OPTherapie, ' .
               [...]
               ' OP2RevisionIndikation, ' .
               ' OP2RevisionArt, ' .
               [...]
               'VALUES (' .
               " '$iPatientID', " .
               " '$sessionID', " .
               " now(), " .
               " '$iUserID', " .
               " '$Datum', " .
               " '$DurchfuehrungVerantwortung', ".
               " '$rev', " .
               " '$OPTherapie',  " .
               [...]
               " '$OP2RevisionIndikation', " .
               " '$OP2RevisionArt', " .
               [...]

现在,如前所述,这就相当于将值“1,2”正确地保存到数据库中。
现在我的问题是:
reading方法允许将单个数据库条目(如“3”)显示为其原始形式“weight regain”,但不能显示“1,2”-没有显示任何内容(因为我没有分解它们)。
我必须在哪里分解它们,以便重新显示原始用户选择?
用“,”代替e。g、 ''(一。e。如果没有逗号,仅仅是一个空格)是否会出现读取和显示数据库条目的问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题