Why is only one select filled?

Asked

Viewed 42 times

0

Well, the following is what I want is to show all the teams, from one table, in that table each row corresponds to one team. However what I wanted to do was show 1 <select> for each team, that is, if there are 4 teams in the comic book I want 4 <select> and each with the 4 teams to choose from.

I have a problem that only one of <select> is that it gets filled.

inserir a descrição da imagem aqui

My code is this::

<?php
$procura3 = mysqli_query($link, "SELECT * from $tabelatorneio");

while($contador < 4){
?>
    <select>
<?php
    while($array3 = mysqli_fetch_array($procura3)){
?>
        <option value="<?php echo $array3["nomeequipa"]; ?>">
            <?php echo $array3["nomeequipa"]; ?>
        </option>
<?php
    }
?>
    </select>
<?php
    $contador ++;
}
?>

What I did wrong, to only show 1 select with all teams?

1 answer

1


The problem that the fetch has already been made all for first whole. The second time you pass the counter loop, mysqli_fetch_array returns false, all lines of $procura3 have been read. It is necessary to redo the consultation.

<?php

while($contador < 4) {
  $procura3 = mysqli_query($link, "SELECT * from $tabelatorneio");
?>

<select>
<?php while($array3 = mysqli_fetch_array($procura3)){ ?>
  <option value="<?= $array3["nomeequipa"]; ?>"><?= echo $array3["nomeequipa"]; ?></option>
<?php } // fecha while do fetch ?>
</select>
<?php
 $contador ++;
} //fecha while do contador ?>
  • The error continues, but now only 4 inputs appear but without the names of the football teams.

  • I got it! Thank you.

  • Replace <?= with <?php echo

  • If I want to assign an input text to every two selects how can I do?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.