如何进行多重选择来创建新行?

发布于 2024-09-09 00:12:32 字数 198 浏览 5 评论 0原文

我有这样的代码:

<select name="team[]" size="8" multiple="multiple">$team</select>

它列出了该团队中的球员,我希望当用户单击球员时,它会创建一个新行,我可以在其中输入有关球员的基本信息,我将通过 php 将其添加到数据库中。

I have this code:

<select name="team[]" size="8" multiple="multiple">$team</select>

It lists for example players in that team, I want when user clicks on player it creates a new row where I can input basic info about player which I will add to database via php.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剪不断理还乱 2024-09-16 00:12:32

如果我正确理解这个问题,这更多的是关于如何设计表格和编写 php,而不是 HTML 或 jQuery。

如果您有一个像这样的表:

table players:
player_id  int
first_name varchar(30)
last_name  varchar(60)

和另一个像这样的表:

table game_player_info:
id          int
player_id   int
goals       int
assists     int
penalties   int
notes       varchar(256)

然后您可以将玩家拉出并填充组合框。您将生成的 HTML 如下所示:

<select name="player">
    <option value="{put player_id here}">{put player name here}</option>
    <option value="{put player_id here}">{put player name here}</option>
    <option value="{put player_id here}">{put player name here}</option>
</select>

<input type="text" name="goals"/>
<input type="text" name="assists"/>
<input type="text" name="penalties"/>
<textarea name="notes" rows="2" cols="20"></textarea>

然后,当您提交时,您可以使用类似这样的查询进行 sql 调用(您可能想要检查错误和 sql 注入,但这是一个简单的示例)

insert into game_player_info (player_id, goals, assists, penalties, notes) 
  values ($_POST['player'], $_POST['goals'], $_POST['assists'], 
  $_POST['penalties'], $_POST['notes'])

:这有帮助。如果这不能回答您的问题,请务必发布更多信息以便清楚起见。

If I understand this question correctly, this is more about how you design your table and write your php than the HTML or the jQuery.

If you have a table like this:

table players:
player_id  int
first_name varchar(30)
last_name  varchar(60)

And another table like this:

table game_player_info:
id          int
player_id   int
goals       int
assists     int
penalties   int
notes       varchar(256)

Then you could pull the players out and populate the combo box. The HTML you would generate would be something like this:

<select name="player">
    <option value="{put player_id here}">{put player name here}</option>
    <option value="{put player_id here}">{put player name here}</option>
    <option value="{put player_id here}">{put player name here}</option>
</select>

<input type="text" name="goals"/>
<input type="text" name="assists"/>
<input type="text" name="penalties"/>
<textarea name="notes" rows="2" cols="20"></textarea>

Then, when you submit, you could do a sql call with a query something like this (you would want to check for errors and sql injection, but this is a simple example):

insert into game_player_info (player_id, goals, assists, penalties, notes) 
  values ($_POST['player'], $_POST['goals'], $_POST['assists'], 
  $_POST['penalties'], $_POST['notes'])

Hope this helps. If this does not answer your question, be sure to post more information for clarity.

初懵 2024-09-16 00:12:32

我想是这样的,只是根据玩家的 id 或其他东西来调用。

$(文档).ready(function(){

$("a").click(function(event){
    $("<input>", {

     id: "playerName",
     type: "text",
     value: "playerName"    

    }).appendTo('form');
});

});

something like this I suppose and just call based on an id or something for the player.

$(document).ready(function(){

$("a").click(function(event){
    $("<input>", {

     id: "playerName",
     type: "text",
     value: "playerName"    

    }).appendTo('form');
});

});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文