douyi1084 2015-08-23 02:12
浏览 175

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

Just want to know how to find the match value on the dropdown list and display the value as current selected for update.

this is my table query and displayed on page with update link beside each row. All update link is working and the value displayed on hidden textbox. My problem is just on one column $trandescription, this will be post on dropdown.

this is my display table.

  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> ";

this is my update page

  <?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.
        ?>

this is my dropdown list on the update page

   <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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题