每次更改列表之前,我都会尝试编辑选择列表。我想要做的是将已经存在的列表更改为另一个列表,由一个 php 函数调用,该列表从第一个列表和一个 sql 数据库中生成一个新信息列表。
很难解释,所以这是我的代码:
我的代码的基础
//php & html
....
$cli = lastNameList(); //first list
$tli = firstNameList(); //second list
echo"
$cli
<div id='editHtml'>$tli</div>
";
....
函数 (php)
//the functions
function lastNameList(){
$options="<select id='lastNames'>";
$sql="SELECT * FROM lastName";
$result=mysql_query($sql);
$options.="<option value='blank'>-- last names --</option>" ;
while ($row=mysql_fetch_array($result)) {
$name=$row["name"];
$options.="<option value='$name'>$name</option>";
}
$options.= "</SELECT>";
return "$options";
}
function firstNameList(){
$options="<select id='firstNames' style='margin-right:40px;'>";
这里有问题:
$sql="SELECT DISTINCT Name FROM firstName WHERE LastName ='lastNameSelectedGoesHere'";
//how do i get the value of the last name so i could make a query for it?
//using distinct to make sure there are no duplicates
$result=mysql_query($sql);
$options.="<option value='blank'>-- first name --</option>" ;
while ($row=mysql_fetch_array($result)) {
$name=$row["Name"];
$options.="<option value='$name'>$name</option>";
}
$options.= "</SELECT>";
return "$options";
}
js(如果重要,在 php 文件中)
echo" <script type='text/javascript'>
$('#lastNames').change(function() {
document.getElementById('eTech').innerHTML=";
$ll = firstNameList();
echo"$ll;
});";
所以你可以看到我的js文件在一个php文件中,它确实有效,我试图在那里做的是生成一个新的名字列表来替换旧的,但我失败了......任何人都有答案或建议我应该怎么做?