很难用另一个选择框中的选定值的ID填充文本框。
这是目前表格中的代码:
<div class="form-group row">
<label for="AssetType" class="col-sm-2 col-form-label">Asset Type</label>
<div class="col-sm-10">
<?php
require 'includes/connection.php';
$sql = "SELECT AssetType FROM tblAssetsType";
$result = mysqli_query($conn, $sql);
?>
<select name="assettype">
<option selected="selected" disabled="disabled">Select an Asset Type</option>
<?php while($row = mysqli_fetch_array($result)):; ?>
<option><?php echo $row[0]; ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<div class="form-group row">
<label for="AssetTypeID" class="col-sm-2 col-form-label">Asset Type ID</label>
<div class="col-sm-10">
<?php
require 'includes/connection.php';
$sql = "SELECT * FROM tblAssetsType WHERE AssetTypeID = 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["AssetTypeID"];
}
} else {
echo "0 results";
}
?>
</div>
</div>
上面的代码运行良好,当我手动将其指向ID#时,会将正确的数据拉回来。我现在似乎无法想象的是如何用与所选资产类型的ID匹配的值替换该值。
简而言之,我需要的是:
<div class="form-group row">
<label for="AssetTypeID" class="col-sm-2 col-form-label">Asset Type ID</label>
<div class="col-sm-10">
<?php
require 'includes/connection.php';
$sql = "SELECT * FROM tblAssetsType WHERE AssetTypeID = ID of selected option below";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<input type="text" name="id" value="'. Unknown Parameter . '">';
}
} else {
echo "0 results";
}
?>
</div>
</div>
如果有更好的方法,或者我不理解任何方向,我们非常感激。
感谢,