doumin1897 2016-12-10 03:03
浏览 28
已采纳

如何使用MySql从phy中的comboBox中获取选定的值?

I'm trying to get the selected value from my comboBox in PHP inside a while loop fetching MySQL results. How could I do it?

<?php
    include ("../conex.php");

    $conSql = ("CALL LISTAR_ASIGNATURAS()");
    $datos=mysqli_query($conex,$conSql);

    echo "<a style='font-size:16px;' href='../index.html'>Volver Atras</a>";
    echo " "; 
    echo "<select name='asigna' id='y' style='width:280px; height:23px;'>"; 
    echo "<option value='0'>Seleccione una Asignatura...</option>";

    while($fila=mysqli_fetch_assoc($datos)) {   
        echo "<option value='".$fila["cod_asignatura"]."'>".$fila["nom_asignatura"]. "</option>";
    }
    echo "</select>";
    echo " ";

    echo "<input type='submit' onclick=location.href='listarasig2.php?codA=".$selected_val."' value='Buscar'>";
?>
  • 写回答

1条回答 默认 最新

  • douyou2368 2016-12-10 03:46
    关注

    You could do something like this in jQuery.

    $('#testCombo').change(function() {
      var cboValue = this.value;
      var link;
      link = "location.href='listarasig2.php?codA=" + cboValue;
      $('#testSubmit').attr('onclick', link);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <select id="testCombo">
      <option value="0">test0</option>
      <option value="1">test1</option>
      <option value="2">test2</option>
      <option value="3">test3</option>
    </select>
    
    <input type="submit" id="testSubmit" />

    or if you still want to use PHP, you could do something like this.

    echo "<a style='font-size:16px;' href='../index.html'>Volver Atras</a>";
    echo " <form action='' method='get'>";
    echo "<select name='asigna' id='y' style='width:280px; height:23px;'>";
    echo "<option value='0'>Seleccione una Asignatura...</option>";
    while ($fila = mysqli_fetch_assoc($datos)) {
      echo "<option value='".$fila["cod_asignatura"].
      "'>".$fila["nom_asignatura"].
      "</option>";
    }
    echo "</select>";
    echo " ";
    echo "<input type='submit' value='Get Value'>";
    echo "</form>";
    echo "<input type='submit' onclick=location.href='listarasig2.php?codA=".$_GET['asigna'].
    "' value='Buscar'>";

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目