正如标题所示,我需要我的下拉框在用户点击提交后保持其值,而不是设置回该值。我已经上传了整个代码,以便更好地了解问题所在,因为我使用 mysql 查询来填充下拉列表。
<?php
$host = "localhost";
$username = "root";
$pass = "";
$database = "database_camcalc";
$conn = mysql_connect($host, $username, $pass) or die (mysql_error());
mysql_select_db($database, $conn);
$query = "SELECT camera FROM camlist";
$result = mysql_query($query) or die (mysql_error());
if (isset($_POST['cameraDD']))
{
$camSelect = $_POST['cameraDD'];
}else{
$camSelect = 'SNV-5200';
}
$dropdown = "Select Camera: <select name='cameraDD' value='$camSelect' onchange='this.form.submit()'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n\<option value='{$row['camera']}'>{$row['camera']}</option>";
}
$dropdown .= "\r\n</select>";
$horiQuery = mysql_query("SELECT hori FROM camlist WHERE camera = '$camSelect'");
if (!$horiQuery) {
die("Failed: " . mysql_error());
}
$hori = mysql_fetch_row($horiQuery);
$sensorSize = mysql_query("SELECT sensor_size FROM camlist WHERE camera = '$camSelect'");
if (!$sensorSize) {
die("Failed: " . mysql_error());
}
$sensorQuery = mysql_query("SELECT camlist.width FROM camlist WHERE camlist.camera = '$camSelect'");
$sensorRow = mysql_fetch_array($sensorQuery);
$sensorWidth = floatval($sensorRow['width']);
$horiFOV = 20;
$distObj = 35;
echo "<form method='POST'>",
"Horizontal Field of View: <input type='text' name='horizontalFOV' value='$horiFOV'>",
"<br />",
"Distance to Object: <input type='text' name='distToObj' value='$distObj'>",
"<br />",
$dropdown,
"<br />",
"<input type='submit' name='submit'>",
"<br />";
if (isset($_POST['submit']))
{
$horiFOV = $_POST['horizontalFOV'];
}
$lensCalc = ($distObj / $horiFOV) * $sensorWidth;
$ppfCalc = $hori[0] / $horiFOV;
echo "<div style ='float:left; width:100%;'>Selected Camera: $camSelect</div>";
echo "<div style ='float:left; width:100%;'>Selected FOV: $horiFOV ft</div>";
echo '<div style ="float:left; width:100%;">',
'Pixels Per Foot: ',
round($ppfCalc),
'</div>';
if ($ppfCalc < 19){
echo "Level of detail: Too Low";
}elseif ($ppfCalc >= 19 and $ppfCalc <=39){
echo "Level of detail: Observation";
}elseif ($ppfCalc >=40 and $ppfCalc <=59){
echo "Level of detail: Forensic Review";
}elseif ($ppfCalc >=60 and $ppfCalc <=79){
echo "Level of detail: Identification";
}elseif ($ppfCalc >=80 and $ppfCalc <=500){
echo "Level of detail: Fine";
}
echo "<div style ='float:left; width:100%;'>Lens focal length: $lensCalc MM</div>";
?>
任何帮助将不胜感激!提前致谢。