如何在下拉列表中自动查找匹配值和显示值

时间:2015-08-23 02:12:06

标签: php drop-down-menu html-select

只想知道如何在下拉列表中找到匹配值,并将值显示为当前选择进行更新的值。

这是我的表查询,显示在页面上,每行旁边都有更新链接。所有更新链接都正常工作,隐藏文本框中显示的值。我的问题只在一列$ trandescription上,这将在下拉列表中发布。

这是我的展示桌。

  while($row = mysql_fetch_array($query)) 
  {
  echo "
  <tr>
  <td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
  <td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
  <td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
  <td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
  <td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
  <td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
  <td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
  <td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
  <span class='glyphicon glyphicon-trash'></span></a></button></td>
  </tr> ";

这是我的更新页面

  <?php
        if (isset($_GET['update'])) 
        {

        $id = $_GET['update'];

        $query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
        $count = mysql_num_rows($query);    

        while ($rows = mysql_fetch_array($query)) {

        $id = $rows['id'];
        $tranid = $rows['tranid'];
        $trandate = $rows['trandate'];
        $patientid = $rows['patientid'];
        $transactiontype = $rows['transactiontype'];
        $trandescription = $rows['trandescription'];
        $tranquantity = $rows['tranquantity'];
        $tranunitprice = $rows['tranunitprice'];
        $tranamount =$rows['tranamount'];
        $gettrandescription = $rows['trandescription'];

        }

}

        ?>

        <form action="billindex.php" method="POST">

        <input type="hidden" name="id" value="<?php echo "$id"; ?>">
        <input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
        <input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
        <input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
        <input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
        <input type="text" name="trandescription" value="<?php echo "$trandescription"; ?>">
        <input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
        <input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
        <input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
        <input type="submit" name="update" value="Update">

        </form>

        <?php
        echo "$trandescription"; // find the match value on dropdown list and display this value.
        ?>

这是我在更新页面上的下拉列表

   <div class="panel panel-default">
        <div class="panel-heading" role="tab" id="headingTwo">
        <h4 class="panel-title">
        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
        Medicine
        </a>
        </h4>
        </div>
        <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
        <div class="panel-body">
        <form action="transaction.php" method="POST">
        <div class="col-md-6">
        <div class="panel panel-info">
        <div class="panel-heading"><h7>Medicine Type : </h7></div>
        <div class="panel-body">
        <select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
        <option id="0" style="width:100px"></option>
        <?php

        $medicine = mysql_query("SELECT * FROM medicine");
        while ($row = mysql_fetch_array($medicine)) {
        echo '<option id="' . $row['medicinename']  . '"';
        echo ' value="' . $row['medicineid'] . '"';
        if($row['medicineid'] == $row['medicinename']) {
        echo ' selected="selected"'; 
        }
        echo '>';
        echo $row['medicinename'];
        echo '</option>';               
        }
        ?>
        </select>
        </div>
        </div>
        </div>          

0 个答案:

没有答案