Why is only one select filled out?

0

Well, this is what I want to show all teams, from a table, in this table each line corresponds to a team. However, what I wanted to do was show 1 <select> for each team, that is, if I have 4 teams in BD I want 4 <select> and each one with 4 teams to choose.

I have a problem that only one of the <select> is filled in.

Mycodeisasfollows:

<?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 did I do wrong, just to just show 1 select with all the teams?

    
asked by anonymous 26.08.2016 / 22:18

1 answer

1

The problem that fetch has already been made all for first integer. The second time it passes the counter loop, mysqli_fetch_array returns false, for all $ search3 lines have already been read. You need to redo the query.

<?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 ?>
    
26.08.2016 / 22:46