我是一名初级 PHP 程序员。我设法将以下代码放在一起,它从 MySQL 数据库创建了一个双下拉列表。在第一个框中,您应该选择索赔中心,在第二个框中,您应该选择一名律师,该律师向第一个框中的中心报告。
我的问题是它没有保留第一个下拉框的选择,因此所有律师都在第二个框中。谁能告诉我我做错了什么?
这是我的代码:
<?php
require_once('appvars.php');
require_once('connectvars.php');
require_once('header.php');
?>
<head>
<script language=JavaScript>
function reload(form) {
var selected_value=form.hub.options[form.hub.options.selectedIndex].value;
self.location='registera.php?hub=' + selected_value ;
}
</script>
<head>
<?php
@$hub=$HTTP_GET_VARS['hub'];
if(strlen($hub) > 0 and !is_numeric($hub)){
echo "INVALID DATA.";
exit;
}
//This fetches content from CLAIMS HUBA table first to get the ATTORNEY list
$hub_query=mysql_query("SELECT DISTINCT hub_name, hub_id FROM claims_huba order by hub_name");
if(isset($hub) and strlen($hub) > 0) {
echo "Loaded: Claims Hubs.";
// If the numeric value of "hub" (selected attorney) is greater than zero we are OK
// Then we will perform an SQL query to find all attorneys with that number.
$attorney_query=mysql_query("SELECT DISTINCT firm_name FROM claims_hub where hub_id=$hub order by firm_name");
echo "Loaded: Attorney Firms by Hub ID.";
}else {
$attorney_query=mysql_query("SELECT DISTINCT firm_name FROM claims_hub order by firm_name");
echo "Loaded: Attorneys.";
}
echo "<form method=post name=f1 action='register_ui.php'>";
echo "<select name='hub' onchange=\"reload(this.form)\"><option value=''>Please select the Claims Hub you are reporting to:</option>"."<BR>";
while($qresult_hub = mysql_fetch_array($hub_query)) {
if($qresult_hub['hub_id']==@$hub){echo "<option selected value='$qresult_hub[hub_id]'>$qresult_hub[hub_name]</option>"."<BR>";}
else{echo "<option value='$qresult_hub[hub_id]'>$qresult_hub[hub_name]</option>";}
}
echo "</select>";
echo "<select name='attorney'><option value=''>Please select your firm: </option>";
while($qresult_attorney = mysql_fetch_array($attorney_query)) {
echo "Loaded: Attorneys queried.";
echo "<option value='$qresult_attorney[firm_name]'>$qresult_attorney[firm_name]</option>";
}
echo "</select>";
echo "<input type=submit value=Submit>";
echo "</form>";
?>