DROPLIST DOWN,LOOP WHILE,外键

时间:2019-01-17 19:48:24

标签: php

我想显示2个下拉列表。我的2个下拉列表实际上是2个外键(fk_candidat, fk_course)。 我目前只能恢复1个外键,即fk_candidat

以下是一个示例

enter image description here

<form action="add_facture.php" method="POST">
  <table>
    <tr>
      <td>Date:</td>
      <td><input type="date" name="dateSaisie" style="width:142px"></td>
    </tr>
    <tr>
      <td>Candidat:</td>
      <td>
        <select name="fk_candidat" style="width:148px">
<?php
while($row = $sql->fetch()) {
?>
          <option value="<?= $row['id_candidat']; ?>"><?= $row['name_candidat'];?>&nbsp;<?= $row['firstname_candidat'];?></option>
<?php
}
?>
        </select>
    <tr>
      <td>Id cours:</td>
      <td><input type="text" name="id_course" /></td>
    </tr>
    <tr>
      <td colspan="2">
        <input class="button" type="submit" value="Ajouter"/>
      </td>
    </tr>
  </table>
</form>

我的问题在这里,如何为外键fk_course创建下拉列表?

1 个答案:

答案 0 :(得分:1)

为什么不使用foreach?

在选择代码中尝试以下代码:

   foreach ($row as $key) {
    echo '<option value="'.$key->id_candidat.'">';
    echo $key->name_candidat .' '.$key->firstname_candidat;
    echo'</option>';
   } 

然后您可以在另一个下拉菜单中重复该操作。

相关问题