doudao3170 2018-06-12 19:53
浏览 28

<option>不会插入<select>

Why other options aren't in ?

<select name="to">
    <?php
         foreach($students as $student) {
    ?>
           <option value="<?php echo($student['name'] . ' ' . $student['surname']); ?>"><?php echo($student["name"] . " " . $student["surname"]); ?></option>
           <input type="hidden" name="name" value="<?php echo($student['name']);?>">
           <input type="hidden" name="surname" value="<?php echo($student['surname']);?>">
    <?php
         }

         foreach($teachers as $teacher) {
    ?>
           <option value="<?php echo($teacher['name'] . ' ' . $teacher['surname']); ?>"><?php echo($teacher["name"] . " " . $teacher["surname"]); ?></option>
           <input type="hidden" name="name" value="<?php echo($student['name']);?>">
           <input type="hidden" name="surname" value="<?php echo($student['surname']);?>">
    <?php
         }
    ?>
</select>

That is how it looks:

<select name="to">
      <option value="BOBO BO">BOBO BO</option>
      <input type="hidden" name="name" value="BOBO">
      <input type="hidden" name="surname" value="BO">
      <option value="XD MAN">XD MAN</option>
      <input type="hidden" name="name" value="XD">
      <input type="hidden" name="surname" value="MAN">
      <option value="IVA OVOO">IVA OVOO</option>
      <input type="hidden" name="name" value="XD">
      <input type="hidden" name="surname" value="MAN">
      <option value="LOKO LOOKO">LOKO LOOKO</option>
      <input type="hidden" name="name" value="XD">
      <input type="hidden" name="surname" value="MAN">
</select>

And why is XD MAN under two another person?

I have to get name and surname separately, that is why I save them to hidden input.

  • 写回答

1条回答 默认 最新

  • douzhang5984 2018-06-12 20:08
    关注

    There are multiple issues with your PHP code:

    1.) In the second foreach you still use $student in the second and third echo. Thats why you get the same name again and again.
    BTW you don't have to use parenthesis with echo.

    2.) Like other people already commented on your question: The output is invalid HTML anyways, which is probably the reason why your browser is not displaying all <option>s correctly. You just cannot have <input>s inside of a <select>.
    Why don't you just use some special character (lets say +) to separate the name and the surname in the <option>s value attribute and then use explode('+',$_POST['to']) (or $_GET respectively) when you get the results back on the server? This way you could get the name and surname separately.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题