简体   繁体   中英

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. I am having difficulties figuring out how I can INSERT a particular player and assign it to that user. 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?

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.

I think you want them to be text type. You better type your inputs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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