从下拉选择标签中获取id以放入链接中



我有一个患者的下拉选择标签:

<select>
<?php
$qPatient = mysql_query("SELECT idpatients, firstName, mi, lastName, suffix FROM patients ORDER BY lastName ASC");  
while($rowPatient = mysql_fetch_array( $qPatient )) {
if(isset($rowPatient['suffix']) && !empty($rowPatient['suffix'])){$suffix = " " . $rowPatient['suffix'];}else{$suffix = NULL;}
            if(isset($rowPatient['mi']) && !empty($rowPatient['mi'])){$mi = " " . $rowPatient['mi'] . ".";}else{$mi = NULL;}
            echo "<option value=" . $rowPatient['idpatients'] . $rowPatient . ">" . $rowPatient['lastName'] . $suffix . ", " . $rowPatient['firstName'] . $mi . "</option>";
        }
    ?>
</select>

这将从下拉列表中生成一个患者列表。如何根据下拉列表中的选择获得要放到链接中的patientID ?

ex: <a href="update.php?patientID=$idpatients">Update</a>

where $idpatients =从下拉列表中选择的患者ID。

另外,我需要有3个不同的链接:1.)update.php 2.) chart.php和3.)report.php

设置此表单方法为GET。提交后,select字段的值将显示为get变量。因此,将name添加到select:

<select name="parientId">

和适当的动作,你的形式:

<form action="update.php" method="GET">

当然还有提交按钮。

这是"静态方式"与形式"。如果你确定你想要链接,而不是提交按钮,你可以使用jQuery:

$("#go").click(function(){ $("#idOfYourForm").submit(); }
...
<a href="" id="go">Go !</a>

或者在<select...>上捕获.change()(抱歉,不是select())并设置$("#go").attr('href','update.php?patientId='+$("#yourSelectId").val());

注:只从SQL中获取您需要的字段,而不是*

<form...>
<select name="patientId" id="patientSelect">
...
</select>
<a id="updatelink" href="">....</a>
<a id="deletelink" href="">....</a>
<script  type="text/javascript">
$(document).ready(function(){
  $("#patientSelect").change(function(){
    $("#updatelink").attr('href',"update.php?id="+$("#parientSelect").val());
    $("#deletelink").attr('href',"delete.php?id="+$("#parientSelect").val());
  }
});
</script>

类似的东西,写得很快,没有检查/测试