简体   繁体   English

数组问题

[英]Issues with array

I have a list of inputs like this...我有一个这样的输入列表......

输入

The blue area is where user names would be listed.蓝色区域是列出用户名的地方。 The input fields are for adding players.输入字段用于添加玩家。 Each user has a total of 13 players.每个用户共有 13 名玩家。 I am having difficulties figuring out how I can INSERT a particular player and assign it to that user.我很难弄清楚如何INSERT特定播放器并将其分配给该用户。 I was told I could do this with arrays.有人告诉我我可以用数组来做到这一点。

I have always struggled with arrays and am not sure how to do this.我一直在与数组作斗争,但不知道如何做到这一点。 I created this as an attempt, but do not know what to do next or if this is even correct.我创建它是为了尝试,但不知道下一步该怎么做,或者这是否正确。

<?php
$playerArray = array();
while($row = mysqli_fetch_array($stmt)) {
$playerArray[] = $row['player_name'];
}
?>

<input class="draftBorder" value='<?php echo $player1; ?>'/>
            <input name="$playerArray[]" "class="draftBorder" value='<?php echo $player2; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player3; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player4; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player5; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player6; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player7; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player8; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player9; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player10; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player11; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player12; ?>'/>
            <input name="$playerArray[]" class="draftBorder" value='<?php echo $player13; ?>'/>

Am I going about this the correct way with the array?我是否以正确的方式处理数组? How would I INSERT this with the array to be associated with the user the player was entered under?我如何将它INSERT到与玩家输入的用户相关联的数组中?

I think you don't understand how to use array.我想你不明白如何使用数组。 Is this helping you ?这对你有帮助吗?

$i = 1;

while($row = mysqli_fetch_array($stmt)) {

$playerArray = $row['player_name'];
$valueInput = $player."".$i;
echo "<input name='$playerArray' 'class='draftBorder' value='$valueInput'/>";
$i++;
}

For all players in your query you'll have an input which value will be $player1, $player2 etc.对于查询中的所有玩家,您将有一个输入,其值将是 $player1、$player2 等。

I think you want them to be text type.我认为您希望它们是text类型。 You better type your inputs你最好输入你的输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM