我想利用现有的插入表单作为编辑表单,供用户对现有记录进行任何更改,以下编码获取从另一种表单传递的值
<?php $error=""; if (isset($_GET['id'])) { $id=$_GET['id']; include checkpo.php';
if (checkpono($id)==true && checkpostatus($id)==true) {
include 'db.php';
$select_PO=mysql_query("SELECT pono, bu, dept, dor, quote1, quote2, quote3 FROM tb_po WHERE pono = '". $id ."' AND postatus !='Approved' AND pono NOT IN (SELECT pono FROM tb_postatus)", $conn);
$count=mysql_num_rows($select_PO);
if ($count == 1) {
$row=mysql_fetch_array($select_PO);
}
mysql_close($conn);
}
else {
die("The PO No. ". $id ." does not allow to edit <a href='searchpo.php'>Return</a> to previous page.");
}}
但我不知道如何在组合框中设置所选值并允许用户进行更改。 对不起,我想要的是,组合框中的值(来自mysql)&#34; dept&#34; &#34; HR&#34;,&#34; Admin&#34;,Finance&#34;和&#34; PR&#34;当记录传递给这个表格时,选择的值(即&#34; HR&#34;)在组合框&#34; dept&#34;这是在mysql之前发布的,所以当用户选择下拉菜单时,他们可以改变来自&#34; HR&#34;,&#34; Admin&#34;,Finance&#34;和&#34; PR&#34;。
<?php
include 'db.php';
$query = "SELECT dept FROM tb_dept";
$result = mysql_query($query);
?>
<select id="dept" name="dept" style="width: 126px">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['dept'];?>"> <?php echo $line['dept'];?></option>
<?php }
?>
</select>
答案 0 :(得分:0)
您需要在选项标记内使用if条件,如此
<强> <option value="<?php echo $line['dept'];?>" <?php if($line['dept']==$matching variable){ echo 'selected'}?>> <?php echo $line['dept'];?></option>
强>
所选属性将显示匹配值时选择的选项