如何在下拉列表中使用选定的

时间:2017-05-11 06:42:36

标签: php

我不知道我应该如何解释我的问题。但我会尽我所能。我目前正在尝试制作更新表格。当用户点击编辑图标时,他们将被定向到编辑表单并携带值。我使用'typeid'来携带值。我的下拉有问题。我使用了选中但值重复。

dropdown

所以我试图解决这个问题,但知道如何解决它。我只能使用PHP而且我不是php的专家。

<div class="form-group">
<label>Choose Vehicle Type Status</label>
    <select class="form-control" name="status" required class="form-control" value="<? php if(isset($row['status_vehicleType'])){ echo $status; } ?>">
     <option value="">Select Vehicle Type</option>

     <option value=<?php echo $row['status_vehicleType']; ?> <?php if($_GET["typeid"]==$row['status_vehicleType']){ ?> selected <?php } ?> ><?php echo $status; ?></option>
       <option value="1">Enabled</option>
       <option value="0">Disabled</option>
</select>

}

上面的

是我用来携带值的typeid。

Option Explicit

Public Function Dependency(x As String) As String

Dim pt          As PivotTable
Dim ptNameFld   As PivotField
Dim ptPermFld   As PivotField
Dim C           As Range

' set the Pivto-Table object, modify "Sheet1" with your sheet's name
Set pt = Worksheets("Sheet1").PivotTables("PivotTable1")

' set the Pivot Field "Full Name"
Set ptNameFld = pt.PivotFields("Full Name")

' set the Pivot Field "Permissions"
Set ptPermFld = pt.PivotFields("Permissions")

' loop through all rows in "Full Name" data range
For Each C In ptNameFld.DataRange.Rows
    If C.Value2 Like x Then ' if the name matches "x"
        ' for DEBUG Only
        'Debug.Print ptPermFld.DataRange(C.Row - ptPermFld.LabelRange.Row)

        Dependency = ptPermFld.DataRange(C.Row - ptPermFld.LabelRange.Row) ' get the value of "Permission", of the same row
        Exit For
    End If
Next C

End Function

2 个答案:

答案 0 :(得分:1)

这是这个问题的简单答案

如果您有任何其他问题可以自由地问我,谢谢

   <?php

function selected($x, $y) {

    if ($x == $y) {
        return " selected";
    } else {
        return "";
    }
}


     $sql = "SELECT * FROM vehicletype WHERE id_vehicleType=" . $_GET['typeid'];
    $result = mysqli_query($link, $sql);
    $row = mysqli_fetch_array($result);

     $q_status = $row['status_vehicleType'] ;

    ?>
     <div class="form-group">
                                                <label class="control-label text-inverse" for="name">Status</label>
                                                <select  class="form-control" name="q_status" id="q_status" required=""    autocomplete="off" >
                                                   <option value="1"  <?php echo selected($q_status,"1");?> >Enabled</option>
                                                   <option value="0"  <?php echo selected($q_status,"0");?>  >Disabled</option>
                                                </select>
                                             </div>

答案 1 :(得分:0)

使用下面的代码,(用于测试集$ _GET ['typeid'] = somevalue):

$row=array();
if (isset($_GET['typeid'])) {
$sql = "SELECT * FROM vehicletype WHERE id_vehicleType=" . $_GET['typeid'];
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
}

<div class="form-group">
<label>Choose Vehicle Type Status</label>
<select class="form-control" name="status" required class="form-control">
   <option value="">Select Vehicle Type</option>
   <option value="1" <?php if($row['status_vehicleType']==1){?>selected<?php }?>>Enabled</option>
   <option value="0" <?php if($row['status_vehicleType']==0){?>selected<?php }?>>Disabled</option>
</select>