Jquery填充< table>基于< select> [英] Jquery to populate <table> based on <select>
问题描述
所以我有一个窗体,顶部有一个从mysql表中填入的值。基本上这种形式是允许将球员加入队伍。
So I've got a form with a drop down at the top that is populated with values from a mysql table. Basically this form is to allow the addition of players to a team.
$seasonid = $_SESSION['SEASON_ID'];
$sql="SELECT TEAM_ID, TEAM_NAME FROM TEAMS WHERE SEASON_ID=$seasonid";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$tid=$row["TEAM_ID"];
$tname=$row["TEAM_NAME"];
$options.="<OPTION VALUE=\"$tid\">".$tname;
}
我想做的是从列表中选择一个团队使用TEAM_ID查询数据库,所有来自该团队的玩家都会显示在表单下方的列表中,以便填写表单的人员可以看到他们已经在他们所选择的团队中的谁。
What I'd like to do is when a team is selected from the list the database is queried with the TEAM_ID and all the players from that team are shown in a list below the form so that the person populating the form can see who is already on the team they've selected.
推荐答案
HTML
<select id = 'teamSelect'>....options....</select>
<div id = 'tableContainer'></div>
Javascript
$(function() {
$("#teamSelect").bind("change", function() {
$.ajax({
type: "GET",
url: "path/to/server/script.php",
data: "tid="+$("#teamSelect").val(),
success: function(html) {
$("#tableContainer").html(html);
}
});
});
});
JavaScript代码将对服务器端的php脚本执行ajax请求(在代码中为 path / to / server / script.php
)此脚本将查询您的数据库,并根据需要输出表。所选择的小组将在 $ _ GET
变量'tid'中。
The javascript code will perform an ajax request to a server side php script (in the code it is the path/to/server/script.php
) This script will query your database and simply output the table as you would like it. The team that is selected will be in the $_GET
variable 'tid'.
这篇关于Jquery填充< table>基于< select>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!