Php 使用ajax在不同位置从下拉列表中选择选项后显示检索到的内容

Php 使用ajax在不同位置从下拉列表中选择选项后显示检索到的内容,php,ajax,drop-down-menu,Php,Ajax,Drop Down Menu,我有一个动态内容的表格。 该表包含一个下拉列表,用户需要在其中选择一个选项,然后使用ajax返回显示的数据。 目前它可以工作,但问题是它只在第一行工作。 从第二行的下拉列表中选择后,结果显示在 第一行:“/!!” 表代码 <table class="bordered" > <tr class="bordered"> <?php $qry=mysql_query("SELECT * FROM `order` "); //Check whether the

我有一个动态内容的表格。 该表包含一个下拉列表,用户需要在其中选择一个选项,然后使用ajax返回显示的数据。 目前它可以工作,但问题是它只在第一行工作。 从第二行的下拉列表中选择后,结果显示在 第一行:“/!!”

表代码

<table class="bordered" >
<tr class="bordered">

<?php
$qry=mysql_query("SELECT * 
FROM  `order` ");
    //Check whether the query was successful or not
    $qry1="SELECT * 
FROM  `order` ";
    $result=mysql_query($qry1);
    if(mysql_num_rows($qry)>0){
?>
<th>delete</th><th>edit</th><th>staff info</th><th>staff</th><th>ex</th><th>phone</th><th>name</th><th>id</th><th>quantity</th><th>status</th><th>time</th><th>date</th><th>order number</th><th></th>
</tr>
    <?php
            while($info = mysql_fetch_array( $result )) 
            { 
            $idem = $info['emp_id'];
            $q="select * from empoyee where emp_id= '".$idem."';";
            $r=mysql_query($q);
            ?>
            <tr>
            <td>
            <form method="POST" action="delete_asu.php">
            <input type="image" src="delete1.png" width="25%" height="20%"/>
            <input type="hidden" name="delete_id" value="<?php echo $info['order_num']; ?>" />
            </form></td>
            <td>
            <?php $id=$info['order_num']; 
            echo '<form method="POST" action="update_asu_form.php?id='.$id.'">' ?>
            <input type="image" src="settings-24-128.png" width="20%" height="15%"/>
            </form></td>
            <td id="txtHint"></td>
            <td>

                <select name="users" onchange="showUser(this.value)">
                <option></option>
                <?php

                $sql=mysql_query("SELECT asu_name from asu_staff");
                while($row = mysql_fetch_array($sql)){
                echo "<option>" .$row["asu_name"]. "</option>";
                }

                ?>
                </select>

            </td>
            <?php 
            while($row = mysql_fetch_array( $r )) 
            {
            ?>
            <td><?php echo $row['ex']; ?></td><td><?php echo $row['phone']; ?></td><td><?php echo $row['emp_name']; ?></td><td><?php echo $row['emp_id']; ?></td>
            <?php
            }
            ?>
            <td><?php echo $info['quantity']; ?></td><td><?php echo $info['status']; ?></td>
            <td><?php echo $info['time']; ?></td><td><?php echo $info['date']; ?></td>
            <td><?php echo $info['order_num']; ?></td><td><input type="radio" name="choose" value="<?php echo $info['order_num']; ?>" /></td>
            </tr>
            <?php
            } 
        }
        else echo "<h1>no orders</h1>";
        ?>

</table>

deleteeditstaff InfoStaffExphoneNameQuantityStatusTimeDateOrder编号

select所给出的值是每个选项的value=“”属性中的值。在您的情况下,您需要将显示选项的代码更改为:

<select name="users" onchange="showUser(this.value)">
 <option value="" selected></option>
<?php
   $sql=mysql_query("SELECT asu_name from asu_staff");
   while($row = mysql_fetch_array($sql)){
     echo "<option value=\"".$row["asu_name"]."\">" .$row["asu_name"]. "</option>";
   }

?>
</select>

试试这个


p、 您可以在查询中选择名称为的id,然后在值=”中使用该id“属性。php代码中的查询可以使用id而不是名称。

谢谢您的快速响应:),但实际上这不是我的问题,问题是当我从第二行的下拉列表中选择选项时,第一行显示的内容。我的主要问题不是返回的数据,而是第二行数据的显示。它只适用于第一行:(我没有检查optionn标记没有value=”“属性的select输入的行为,但我认为它们可能总是返回第一个值。此外,您可能希望传递“this”而不是“this.value”然后检查javascript函数中的value属性。甚至可能需要使用“this.options[this.selectedIndex].value”。事实上,这是我的工作,没有值,因为代码是检索选项的内容。非常感谢Arthur,它现在正在工作问题是我使id递增,然后它的工作:D,id值=到行号我通过在while($info=mysql\u fetch\u数组中增加一个值来获取行号(结果美元)){
 $q=$_GET["q"];
            $sql="SELECT * FROM asu_staff WHERE asu_name = '".$q."'";
            $result = mysql_query($sql);
            while($row = mysql_fetch_array($result))
            {
            echo "<table>";
            echo "<tr> <td>" . $row['asu_id'] . " </td><td>staff id</td></tr>";
            echo "<tr> <td>" . $row['phone'] . " </td><td>staff phone</td></tr>";
            echo "</table>";
<select name="users" onchange="showUser(this.value)">
 <option value="" selected></option>
<?php
   $sql=mysql_query("SELECT asu_name from asu_staff");
   while($row = mysql_fetch_array($sql)){
     echo "<option value=\"".$row["asu_name"]."\">" .$row["asu_name"]. "</option>";
   }

?>
</select>